Hello Community
When we create a Work order we have a script that executes every time we select a client. This script is there in order to pre-populate some fields within the form.
Most of the time the script executes perfectly, but sometimes for some reason when the client is selected the users get an error like the following:
ReferenceError: Web resource method does not exist: filterCareServiceLookup at y._handleMethodNotExistError (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:1994:5038) at y.execute (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:1994:3685) at https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:155:26335 at i (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:312:88) at ee._executeIndividualEvent (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:155:26309) at ee._executeEventHandler (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:155:23314) at Object.execute (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:155:22742) at N._executeSyncAction (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:929:692) at N._executeSync (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:929:419) at N.executeAction (https://chaltd.crm11.dynamics.com/uclient/scripts/app.js?v=1.4.3664-2112.1:929:201) Error Details: Event Name: onchange Function Name: filterCareServiceLookup Web Resource Name: new_JS_AssignmentCareServiceLookupFilter Solution Name: Active Publisher Name: DefaultPublisherchaltdsandbox
I log a ticket to Microsoft and they suggested I to try to change the namespace I have in javascript, but this did not stop the issue.
They also mentioned that looking at multiple Work orders, in two separate tabs could affect the script from loading correctly, is this really true?
In my perspective this makes me think that for some reason the resources sometimes are not loaded in the browser, but I am not sure what could be the cause of this. I also can see that there are quite a lot of javascript libraries which we haven't added which are running on load, could the loading of these libraries impact our custom one from loading?
Below you can see the scripts that execute when we select a client
- clientassignment.setBrandFromClient
clientassignment.setBrandFromClient = function (executionContext) {
let formContext = executionContext.getFormContext();
let client = formContext.getAttribute(clientField);
if (client.getValue() != null) {
let clientId = client.getValue()[0].id;
let brandId;
Xrm.WebApi.retrieveRecord(accountEntityName, clientId).then(
function success(result) {
brandId = result._workordertypeid_value;
let lookup = new Array();
lookup[0] = new Object();
lookup[0].id = result._workordertypeid_value;
lookup[0].name = result["_workordertypeid_value@OData.Community.Display.V1.FormattedValue"];
lookup[0].entityType = workOrderTypeEntityName;
clientassignment.setPriceListFromBrand(formContext, brandId);
formContext.getAttribute(brandField).setValue(lookup);
})
}
};
- clientassignment.SetClientName
clientassignment.SetClientName = function (executionContext) {
let formContext = executionContext.getFormContext();
let client = formContext.getAttribute(clientField);
if (client.getValue() != null) {
let clientName = client.getValue()[0].name;
formContext.getAttribute(clientNameField).setValue(clientName);
}
};
- filterCareServiceLookup
clientassignment.filterCareServiceLookup = function(executionContext){
let formContext = executionContext.getFormContext();
try{
if (formContext.getControl(serviceAccount) != null && formContext.getAttribute(serviceAccount).getValue()!=null)
{
cha.clientassignment.GetAccountAssociatedProducts(formContext).then(data=>{
//get the first product
if(data.length==1){
formContext.getAttribute(serviceType).setValue(data);
}
else if (data.length>=0){
const defaultService = [...data];
formContext.getAttribute(serviceType).setValue(defaultService.splice(0,1));
}
fetcXml="";
data.forEach(element => {
fetcXml =""
});
fetcXml ="";
formContext.getControl(serviceType).addPreSearch(function (){
formContext.getControl(serviceType).addCustomFilter(fetcXml);
});
});
}
} catch (e){
throw new Error(e.Message);
}
}