When can we use the Script Actions and purpose of Script Actions can any, can any one give me the real time examples of script actions except service now wiki example?

Shantharao
Kilo Sage

Hi All,

I am new to Script Actions, I want to know the purpose and functionality of script actions how to use it and where to use it?

When can we use the Script Actions and purpose of Script Actions,   can any one give me the real time examples of script actions except service now wiki example?

Kindly help me on this topic

Thanking you in advance.

Best Regards,

Burra

6 REPLIES 6

Alikutty A
Tera Sage

Hi,



Script actions are used to execute any server side scripts asynchronously when an event is triggered. Here are 2 use cases that I can think



1) While performing integrations and you need to send large amount of data/records or attachments to an external system, it cannot be done synchronously as it will affect user experience. In such a scenario, you can call an event from a business rule and trigger the required script in the script action.



2) Suppose you have 200 child incidents tagged to an incident and you need to close all the child incidents when parent is closed. If you follow the OOB approach, it will create system performance issues as the business rule is executed synchronously. In such a case you can call an event and execute the code for closing 200 child incident in a script action.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Hi,



Thanks for the quick response, can you provide me a small real time script actions script for my reference.



Regards,


Burra


Hi Burra,



Please check the below section 2: here you will find one of the example to "creates an email notification for Workflow activity".


http://wiki.servicenow.com/index.php?title=Script_Actions#gsc.tab=0


or you can also check existing OOTB script actions script.


Hope it will help you.



Thanks,


Harshvardhan


You can consider sample 2 that I have explained



1) You will need to call an event from an on-After business rule



gs.eventQueue('incident.child.closure', current, 'event parameter 1','event parameter 2');   //incident.child.closure should be an event created



2) Script action that has selected event as incident.child.closure



var gr = new GlideRecord('incident');


gr.addEncodedQuery('parent_incident='+current.sys_id);   //Query for all child incidents


gr.query();


while(gr.next()){


gr.state = 3;   //close


gr.update();


}



gs.log(event.parm1); //Logs event parameter 1   If you need to pass variables from business rule


gs.log(event.parm2); //Logs event parameter 2



If my response has answered your query, please mark it as correct answer so we can close the thread and others can refer.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response