How to call script include in UI Action

Manasa23
Tera Contributor

HI,

I have created a UI Button , if user clicks on that UI button my script include should Execute... Please help me with the script to call script include from UI Action

Below is the script include :


AjaxClientHelperTest1.prototype = Object.extendsObject(AbstractAjaxProcessor, {

validateExcel: function() {
var ticketSysID = this.getParameter('sysparm_ticketSysID');  
var v_aFinalArr = [];
.

;

 

  Thanks,
M..

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,

There are two things here based on your requirement.

Script include can be called in UI Action using both Client and Server types.

1) If you want to call a Script Include in Server side of UI Action you can use below syntax:

new ScriptIncludeName().FuctionName(parameter if any);

2) Looking at your screenshot looks like you have created a Client callable Script Include so you need to sue below syntax:

 var ga = new GlideAjax('asu_GetLocationData');

      ga.addParam('sysparm_name', 'getCampus');

      ga.addParam('sysparm_buildingid', g_form.getValue("u_building"));

      ga.getXML(updateCampus);

}

     

function updateCampus(response) {

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

}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

4 REPLIES 4

Murthy Ch
Giga Sage

Hi Manasa,

You can call the script include using GlideAjax in your UI action code.

 

Thanks,
Murthy

shloke04
Kilo Patron

Hi,

There are two things here based on your requirement.

Script include can be called in UI Action using both Client and Server types.

1) If you want to call a Script Include in Server side of UI Action you can use below syntax:

new ScriptIncludeName().FuctionName(parameter if any);

2) Looking at your screenshot looks like you have created a Client callable Script Include so you need to sue below syntax:

 var ga = new GlideAjax('asu_GetLocationData');

      ga.addParam('sysparm_name', 'getCampus');

      ga.addParam('sysparm_buildingid', g_form.getValue("u_building"));

      ga.getXML(updateCampus);

}

     

function updateCampus(response) {

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

}

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Also to note one important thing in UI Action if you want to do a Client side behavior in your UI Action then you need to follow couple of important parameters here as shown below:

1) Make sure to define a Action Name and check the Client Check box

find_real_file.png

2) Define on On click function as shown below

3) Sample code shared below on how to call a Script Include in your UI Action in both Client and Server side section in the same UI Script:

find_real_file.png

There is a good article on this , please refer the same for more info:

https://servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

snowycode
Tera Contributor

Hi @Manasa23

 

First things first, make sure you check the 'Client callable' box on the Script Include form, which will automatically format your code to be client callable (as shown below):

 

ScriptExample.png

 

 

Once that's done, you can call the Script Include on the UI Action with the following code:

 

 

new ScriptIncludeName().FunctionName();

 

 

To see what that looks like in the actual UI Action Condition field, see the image below:

 

 

UI Action Condition.png

 

 

And that's it! If you are having trouble with the Script Include/GlideAjax portion, then Shawn Dowler's GlideAjax cheat sheet will help you out.

 

Please mark Correct or Helpful if my response helped you.

You can also find a full guide for how to call a script include from UI Action here.