Dynamics 365:
Microsoft Dynamics 365 is a cloud-based suite of intelligent business applications that helps organizations improve operational efficiency and reduce business complexity by unifying processes, gaining insights, and fostering better customer relationships.
- Microsoft Dynamics 365 CRM form for an entity named “crmorganization.” This form appears to be for creating or editing a record related to an organization or contact.
Village Lookup Dependency:
- The City and Pincode fields seem to depend on the selected Village.
- If the Village is not selected, they might remain empty or disabled.

Select a Village
- Search for a village and select it.
- The City and Pincode should automatically populate (if dependent on Village selection)

Your function is performing well-organized logic to retrieve and set lookup values for suri_city
and suri_pincode
attributes, based on the selected suri_village
value. Here’s a detailed breakdown of its functionality and potential improvements:
Javascript Code:
function village(executionContext) {
var formContext = executionContext.getFormContext();
var village = formContext.getAttribute(“suri_village”).getValue();
if (village != null) {
var Villageid = village[0].id.replace(“{“, “”).replace(“}”, “”); // Clean GUID
Xrm.WebApi.retrieveRecord(“suri_village”, Villageid, “?$select=_suri_city_value,_suri_pincode_value”).then(
function success(result) {
console.log(result);
// Fetch City Lookup
var City = result[“_suri_city_value”];
if (City) {
var CityValue = [{
id: City,
entityType: “suri_city”.toLowerCase(), // Ensure lowercase
name: result[“_suri_city_value@OData.Community.Display.V1.FormattedValue”]
}];
formContext.getAttribute(“suri_city”).setValue(CityValue);
} else {
formContext.getAttribute(“suri_city”).setValue(null);
}
// Fetch Pincode Lookup
var Pincode = result[“_suri_pincode_value”];
if (Pincode) {
var PincodeValue = [{
id: Pincode,
entityType: “suri_pincode”.toLowerCase(), // Ensure lowercase
name: result[“_suri_pincode_value@OData.Community.Display.V1.FormattedValue”]
}];
formContext.getAttribute(“suri_pincode”).setValue(PincodeValue);
} else {
formContext.getAttribute(“suri_pincode”).setValue(null);
}
},
function(error) {
console.error(“Error retrieving data: ” + error.message);
}
);
} else {
// Clear City & Pincode if Village is removed
formContext.getAttribute(“suri_city”).setValue(null);
formContext.getAttribute(“suri_pincode”).setValue(null);
}
}