$(document).ready(function () {
$("#countryField").change(function () {
var countryId = $(this).val();
if (countryId) {
var query = `/api/data/v9.2/new_cities?$filter=_new_country_value eq ${countryId}`;
$.ajax({
url: query,
type: "GET",
headers: {
"OData-MaxVersion": "4.0",
"OData-Version": "4.0",
"Accept": "application/json",
"Content-Type": "application/json",
"Prefer": "odata.include-annotations=\"*\""
},
success: function (data) {
var cityDropdown = $("#cityField");
cityDropdown.empty();
$.each(data.value, function (index, item) {
cityDropdown.append(
$("<option></option>")
.val(item.new_cityid) // City ID
.text(item.new_cityname) // City Name
);
});
},
error: function (err) {
console.log("Error fetching cities: ", err);
}
});
}
});
});
new_cities
is the logical name of your cities entity._new_country_value
is the lookup field that links cities to a country. Adjust this according to your entity schema.new_cityid
and new_cityname
are placeholders for the actual field names of the city entity in Dataverse. Replace these with the correct logical names.
WarrenBelz
146,518
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,692
Most Valuable Professional