Announcements
function SetTitle(executionContext) { var formContext = executionContext.getFormContext(); var ticketnumber = formContext.getAttribute("ticketnumber") var contact = formContext.getAttribute("customerid"); //var regardingObjectDetails = formContext.getAttribute("regardingobjectid").getValue(); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() "/api/data/v9.1/contacts(ContactId)?$select=funds_personid", 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) { if(ticketnumber != null && contact != null){ var result = JSON.parse(this.response); var funds_personid = result["funds_personid"]; var Ticket = ticketnumber.getValue(); var con = contact.getValue()[0].name; var title = formContext.getAttribute("title").setValue(Ticket " " con " " funds_personid) } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
Hey guys I am trying to get this Id field from contact entity and set case title to few values
but Dynamics gives me error ContactID is not defined. could you guys tell what the issue is
Person ID is text field
I idea was not to hard code specific contact record ID it but get the person id based on customer Id select which is a look up to contact
Hi,
I have modified your code. Please replace your code with the code below.
This will solve your issue.
function SetTitle(executionContext) {
var formContext = executionContext.getFormContext();
var ticketnumber = formContext.getAttribute("ticketnumber")
var contact = formContext.getAttribute("customerid").getValue()[0].id.replace("{", "").replace("}", "");
//var regardingObjectDetails = formContext.getAttribute("regardingobjectid").getValue();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts(" + contact + ")?$select=funds_personid", 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) {
if (ticketnumber != null && contact != null) {
var result = JSON.parse(this.response);
var funds_personid = result["funds_personid"];
var Ticket = ticketnumber.getValue();
var con = contact.getValue()[0].name;
var title = formContext.getAttribute("title").setValue(Ticket + " " + con + " " + funds_personid)
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
Thanks
Akanksha
Please mark the answer as Verified if found helpful.
Hi, replace ContactId value as you need
function SetTitle(executionContext) { var formContext = executionContext.getFormContext(); var ticketnumber = formContext.getAttribute("ticketnumber") var contact = formContext.getAttribute("customerid"); //var regardingObjectDetails = formContext.getAttribute("regardingobjectid").getValue(); var ContactId = contact.getValue()?.[0].id.replace(/[{|}]/g, ""); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() `/api/data/v9.1/contacts(${ContactId})?$select=funds_personid`, 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) { if (ticketnumber != null && contact != null) { var result = JSON.parse(this.response); var funds_personid = result["funds_personid"]; var Ticket = ticketnumber.getValue(); var con = contact.getValue()[0].name; var title = formContext.getAttribute("title").setValue(Ticket " " con " " funds_personid) } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
regards.
Hello,
Issue is in the line
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/contacts(ContactId)?$select=funds_personid", true);
to be more specific - ContactId - you should provide the Id of the record you want to get instead of ContactId
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156