Script Action triggered by an event from Business Rule not working

Milan13
Giga Expert

Hello,

I have a business rule, which triggers an event and sends notification after the event is triggered.

This works, however it should also change values of an incident form and this does not work, not sure why...

Business Rule (event triggered, notofcation tied to the BR sent..):

(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);
})(current, previous);

Script Action screen shot below (not working - not setting the values as required....)

Any idea why?

Thanks a lot.

Milan

find_real_file.png

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Milan,

1. Create after UPDATE Business rule and add below code:

(function executeRule(current, previous /*null when async*/) {

if(current.u_off_hold_date != previous.u_off_hold_date){

gs.addInfoMessage("DATE:"+current.u_on_hold_reminder+" Updaated:"+current.sys_updated_on);
gs.eventQueueScheduled ("on.hold.reminder'" , current , gs.getUserID ( ) , gs.getUserName ( ) , current.u_on_hold_reminder) ;

})(current, previous);

2. Add log in script action: add log:

gs.log("Number:"+current.number);
current.state ='9';

current.assigned_to ='sysId of assigned to';
current.udpate();

3. Go to the Event log where you can find out the event when it is processed compare it the the updated date log. 

I think issue is with running timing of event or script action.

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

19 REPLIES 19

SaiRaviKiran Ak
Giga Guru

Add that script in business rule itself after the event call

SaiRaviKiran Ak
Giga Guru

Check below link :

https://community.servicenow.com/community?id=community_question&sys_id=622fb269db58dbc01dcaf3231f96...

 

Your script syntax is not correct. you need create function and put your code. check the link

Business Rule:

(function executeRule(current, previous /*null when async*/) {
gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);
})(current, previous);

 

Event on.hold.reminder gets triggered and notification is sent, after the date/time field on the incident form gets the event triggered I need to set the values up as per below script action and it just does not react...no idea why....thanks a lot.

Script Action:

setFields();

function setFields() {
current.state = 9;
current.assigned_to = "";
current.update();
}

 

Milan

Jaspal Singh
Mega Patron
Mega Patron

Hi Milan,

 

Can you include the code which is currently in script action into the Business rule i.e. after your gs.eventQueue() line.

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

I can't because when I do the values get set before the event gets triggered at given date/time and and I need the values to be set after the event gets triggered..