The CreatorCon Call for Content is officially open! Get started here.

How to call global script include from private application scope

anshul_jain25
Kilo Guru

Hi ,

how to call global script include from private scope application.

below is the client script code which is calling script include from global scope, I want to use same code and call same script include but when working in my private scope.

What changes needs to be made in the code

1 ACCEPTED SOLUTION

johnolivermendo
ServiceNow Employee
ServiceNow Employee

Hey Anshul,



You can try simply adding 'global.' when you initialize the global script include in your scoped app. For example it would look like this:



var scriptInclude = new global.scriptInclude();


View solution in original post

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Anushl,



Globally scoped scripts with 'Accessible' from this scope only' cannot be called from Scoped Applications.



You need to write your own functionality to mimic that script.



NOTE: If you plan on publishing your app, you won't be able to include the scope access change to that script.


    • Changes to globally scoped items will not be included in your Update Set.
    • It will not be certified.

Below is my code...


Can some one convert this code to code with glide ajax as i got to know that we can not use glide record in application scope.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {



if (isLoading || newValue === '') {


          return;


    }




  if(newValue)


  {


    alert('opened for is' + g_form.getValue("opened_for"));


    var loc = new GlideRecord("sys_user");


    loc.addQuery("sys_id",g_form.getValue("opened_for"));


    loc.query();


    if (loc.next())


    {


    g_form.setValue("location",loc.location);


    }


  }//Type appropriate comment here, and begin script below


   


}



I just want to get location field to auto populate on my form as soon as opened for gets changed.


Hey Anshul,



Here's a quick example of using glide Ajax to make a glide record query asynchronously.




function onChange(control, oldValue, newValue, isLoading, isTemplate) {



if (isLoading || newValue === '') {


          return;


    }




  if(newValue)


  {


    alert('opened for is' + g_form.getValue("opened_for"));



var ajax = new GlideAjax('ContextActionsAjax');


ajax.addParam("sysparm_name", "getLabel");


ajax.addParam("sysparm_user_id", g_form.getValue("opened_for"));


ajax.getXml(setLocationValue);




  }//Type appropriate comment here, and begin script below




 


}



function setLocationValue(response) {


      var answer = response.responseXML.documentElement.getAttribute("answer");


      g_form.setValue("location", answer);


}




Create a new script include that extends AbstractAjaxProcessor and put your glide record query there. Something like this:


Screen Shot 2017-04-10 at 10.15.17 AM.JPG