Hi,
The error you are getting is "<yourfunctionname> not defined at eval". This error is mostly to be occurred because of the below 2 reason-
1) You have made changes to your JavaScript library like added a function and have register it on form load, onchange etc but due to caching your browser is loading the old version which did not have this function before.
2) You have some syntax error in your JavaScript file due to which browser failed to load that JavaScript file
Now in both the above scenario, CRM is expecting to call your function but it couldn't find that function hence it is throwing the error saying <function name> not found.
To validate & fix the first scenario, do publish all customization, close your browser session and try agin in a new browser session. Alternatively you can clear browser cache (Google on how to clear browser cache if you are not already aware) or open your CRM in Incognito/ In private session and check again.
After performing the above, the issue will be fixed most liekly but if you are still getting the same error i.e. "<function name> not defined at eval", you are most likely hitting a second scenario where there is a syntax error in your JavaScript library. Do not that after the first scenario, you may get some other error which requires different fix, this one is for the exact same error message.
Now to fix the second scenario, you can use need to review your code and find ou the systax error. Most common problem are missing quotes, commas etc. This can be easily validated by opening your code either in visual studio or any other code editor tool. You can also use Online JavaScript Syntax validator - esprima.org/.../validate.html
Coming back to your code, I verified your code in my visual studio and there were some syntax error. I have updated the code. Could you please try this again and check. Do remember to publish customization and try it in a new browser session just to rule out any caching issues.
========================
function yourFunctionName() {
var lookup = Xrm.Page.getAttribute("new_cdigodesocio").getValue();
var newid = lookup[0].id.slice(1, -1);
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/new_membresaclientes(" + newid + ")?$select=_new_cuenta_value", 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 result = JSON.parse(this.response);
var _new_cuenta_value = result["_new_cuenta_value"];
var _new_cuenta_value_formatted = result["_new_cuenta_value@OData.Community.Display.V1.FormattedValue"];
var _new_cuenta_value_lookuplogicalname = result["_new_cuenta_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
if (_new_cuenta_value != null) {
var value = new Array();
value[0] = new Object();
value[0].id = _new_cuenta_value;
value[0].name = _new_cuenta_value_formatted;
value[0].entityType = _new_cuenta_value_lookuplogicalname;
}
else {
alert("Error: No account found to copy!");
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
========================
Hope this helps.