Script Include and Client Script

shatakshi10
Tera Contributor

There is a variable on service catalog that is targeting to location [cmn_location] table, so If requested for changes location changes too depending on requested for, so if requested for belongs from USA country and his location is "Mesa" then a select box choice should be "True" but if requested for belongs from USA country and his location is "San Diego" then a select box choice should be "false".

I tried creating script include and calling in client script but didnt worked.

5 REPLIES 5

Ashish Parab
Mega Sage

Hello @shatakshi10 ,

 

Could you please elaborate more on your requirement? What should happen if both of the given conditions are not met?

Additionally, could you share what you have tried so far?

 

Thanks,

Ashish

Main Concern is about these options , 

I have a select box from which choices needs to be reflected based on Location

Pavithra0812
Tera Expert

@shatakshi10 

Calling a Script Include in an OnChange Catalog Client Script should work in this scenario. Please share what you've tried so far to ensure we can provide more accurate and helpful answers.

Client Script to set location of user - ServiceNow Community


 getLocation: function() {
        var locsysid = this.getParameter('sysparm_loc_sysid');
        var gr = new GlideRecord("cmn_location");
        gr.addQuery('sys_id', locsysid);
        gr.addEncodedQuery("country=Mexico^ORcountry=Canada^ORcountry=United States of America^nameLIKERemote");
        gr.query();
        if (gr.next()) {
            return 'true';
        } else {
            return 'false';
 }
 var ga = new GlideAjax('restrictingOptionBasedOnLocation');
    ga.addParam('sysparm_name', 'getLocation');
    ga.addParam('sysparm_loc_sysid', newValue);
    ga.getXML(callBackFunction);

    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		alert(answer)
        if (answer == 'true') {
            g_form.removeOption();
            g_form.addOption();
        }
else{            g_form.addOption();
        }
    }