Skip to main content

Notifications

Dynamics 365 Community / Forums / Field Service forum / Intermittent issue wit...
Field Service forum
Unanswered

Intermittent issue with loading scripts

Posted on by 60

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

scripterror.PNG

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?

OnLoadScriptError.PNG

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);
		}

}

 

Categories:
  • Anon Profile Picture
    Anon 2 on at
    Intermittent issue with loading scripts
    Did you ever manage to solve this?
     
    We also started to experience this error occasionally, even though the nature of the error would indicate it either happens all the time or it doesn't at all...
  • M.Barimah Profile Picture
    M.Barimah 60 on at
    RE: Intermittent issue with loading scripts

    any suggestions?

  • M.Barimah Profile Picture
    M.Barimah 60 on at
    RE: Intermittent issue with loading scripts
    [quote user="Steve Zhao"]

    Hi M.Barimah,

    Based on the error message, there should be something wrong with the filterCareServiceLookup() function. However, there is nothing wrong with this function as you provided. Could you provide the code of  GetAccountAssociatedProducts() for further investigation?

    [/quote]

    Hello Steve,

    for some reason is not allowing me to put it in quote tags, here is the content of the GetAccountAssociatedProducts function:

    GetAccountAssociatedProducts= function(formContext){

    return new Promise((resolve,reject) =>{

    var req = new XMLHttpRequest();
    var obj = new Array();
    var accountidvalue = formContext.getAttribute(serviceAccount).getValue()[0].id.replace(/({|})/gm, "");

    // used fetchXML to reduce the number of calls (Account -> ClientProduct ->Product)

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/products?fetchXml=%3Cfetch%20version%3D%221.0%22%20output-format%3D%22xml-platform%22%20mapping%3D%22logical%22%20distinct%3D%22true%22%20%3E%3Centity%20name%3D%22product%22%20%3E%3Clink-entity%20name%3D%22cha_clientproduct%22%20from%3D%22cha_productid%22%20to%3D%22productid%22%20%3E%3Clink-entity%20name%3D%22account%22%20from%3D%22accountid%22%20to%3D%22cha_accountid%22%20%3E%3Cfilter%3E%3Ccondition%20attribute%3D%22accountid%22%20operator%3D%22eq%22%20value%3D%22"+accountidvalue+"%22%20%2F%3E%3C%2Ffilter%3E%3C%2Flink-entity%3E%3C%2Flink-entity%3E%3C%2Fentity%3E%3C%2Ffetch%3E", true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    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).value;

    for (var a = 0; a < result.length; a++) {
    obj.push({
    id: result[a].productid,
    name:result[a].productnumber,
    entityType:"product"
    })
    }

    resolve(obj);

    } else {

    reject('error');
    }
    }
    };
    req.send();

    });


    };

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Intermittent issue with loading scripts

    Hi M.Barimah,

    Based on the error message, there should be something wrong with the filterCareServiceLookup() function. However, there is nothing wrong with this function as you provided. Could you provide the code of  GetAccountAssociatedProducts() for further investigation?

Helpful resources

Quick Links

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Blog subscriptions now enabled!

Follow your favorite blogs

TechTalk: How Dataverse and Microsoft Fabric powers ...

Explore the latest advancements in data export and integration within ...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,860 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,155 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans