Hi All,
I am using below code to set one lookup field
if (formContext.getAttribute("wcl_technicalactivity") !== null)
var technicalactivity = formContext.getAttribute("wcl_technicalactivity").getValue();
if (technicalactivity != null && technicalactivity != undefined) {
// var newid = technicalactivity[0].id.slice(1, -1);
var recordId = formContext.data.entity.attributes.get("wcl_technicalactivity").getValue()[0].id;
var newID = recordId.toLowerCase();
if (newID !== null) {
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/campaignactivities?$select=activityid,_wcl_technicalactivity_value&$filter=_wcl_technicalactivity_value eq '" + newID + "'", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var activityid = results.value[i]["activityid"];
var _wcl_technicalactivity_value = results.value[i]["_wcl_technicalactivity_value"];
var _wcl_technicalactivity_value_formatted = results.value[i]["_wcl_technicalactivity_value@OData.Community.Display.V1.FormattedValue"];
var _wcl_technicalactivity_value_lookuplogicalname = results.value[i]["_wcl_technicalactivity_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (formContext.getAttribute("wcl_catechnicalactivityattendanceid") !== null)
formContext.getAttribute("wcl_catechnicalactivityattendanceid").setValue(activityid); How can it works as activityid is primary key(Record ID)
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
Thanks,
Jharana