Hi all,
I seem to be having a problem where my CRM script is causing an error. I am using Microsoft Dynamics CRM 2016 not 365.
The error is inconsistent, but by using the debugger it seems to be occurring deep in CRM's own code.
Has anyone seen a similar problem to this and know of a solution? I have attached a screenshot and code snippet below.
$.ajax({
type: 'get',
contentType: 'application/json; charset=utf-8',
datatype: 'json',
url: serverUrl + ODATA_ENDPOINT + '/' + odataSetName + "(guid'" + guid + "')" + select,
beforeSend: function(XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader('Accept', 'application/json');
},
success: function(data, textStatus, XmlHttpRequest) {
myglobaloutofcourtsettlement = parseFloat(data.d.rsl_prostype_moneyoocsetoffered);
myglobalfromat = data.d.rsl_prostype_fromat_jurisdictioncourt.Value;
Xrm.Page.getAttribute('rsl_pros_lawtype').setValue(data.d.rsl_prostype_lawtype.Value);
},
error: function(XmlHttpRequest, textStatus, errorThrown) {
//alert("Error " + errorThrown)
alert('Error while retrieving Prosecution Type details; Message: ' + $.parseJSON(XmlHttpRequest.responseText).error.message.value);
}
});
Any help would be greatly appreciated! I'm also happy to answer any questions which may help me solve this issue.
Hi Emily,
Thanks for getting back to me.
I'm afraid I'm still using CRM Dynamics 2016 and not CRM Dynamics 365.
It's all quite complicated, but the exact version of CRM Dynamics which we run has not yet been upgraded to 365.
I just tried using formContext by calling `executionContext.getFormContext();` but my code now errors with "TypeError: executionContext.getFormContext is not a function" so I don't believe that method is support in CRM Dynamics 2016.
Thanks for the response though!
Hi James,
Xrm.Page is retired. You should use new API now. You should use formcontext now.
https://docs.microsoft.com/en-us/power-platform/important-changes-coming
https://alphabold.com/xrm-page-is-deprecated-how-do-i-use-formcontext-in-dynamics-365/
Hi David,
Thanks for the quick reply and the suggestion.
I'm pretty certain it's getAttribute too. It appears to be solely an issue with this attribute, as we are calling getAttribute in a lot of places.
The attribute may or may not be on the form, as we are checking in the onload event.
However, usually, when we want to check if a field exists on the form we would do something like `Xrm.Page.getAttribute(attributeName)` and if that returns null then the field does not exist.
Do you know of another way to safeguard against the field/attribute not existing?
Many thanks!
I'd suggest you split out the code to check which part of this is throwing the error - you're accessing 3 functions in the 1 line (getAttribute, setValue and Value), and if you split this onto 3 separate lines you can be sure which has the problem (based on the error and the debug it looks like getAttribute, but it would be best to be sure)
Then, is the issue solely with this attribute, or does it occur with others ?
Is the attribute on the form, and if so, how many times, and where (main form, header, BPF) ?
When does the code run ? If it's in the onload event, then it may be that not all script has loaded yet
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156