current.update() not working in script action

Milan13
Giga Expert

Hello,

I have a script action which reacts to an event in a business rule, after this event is triggered I need certain fields to be updated, even if the script action reacts to the event according to log, "current" parameters are accessible within the script according to log, current.update() does not work for some reason...

Script action:

gs.log('!!!MILAN - STORY43....');
setFields();

function setFields() {

current.state = '9';
current.short_description = 'Test from script action';
current.assigned_to = "";
gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);
current.update();

}

 

gs.info in log works with the correct values, however what does not work is the current.update() part as the data on the incident form do not get updated..

Any idea why?

Appreciate your help,

Milan

find_real_file.png

Log (gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);

find_real_file.png

 

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Milan,

try out with below code:

var grIncident = new GlideRecord('incident');
grIncident.addQuery('sys_id',current.sys_id);
grIncident.query();
while(grIncident.next()){
grIncident.short_description = "Test from script action";
grIncident.setValue('assigned_to','');
grIncident.update();
}


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

Thank you,
Abhishek Gardade

View solution in original post

14 REPLIES 14

AbhishekGardade
Giga Sage

Hello Milan,

try out with below code:

var grIncident = new GlideRecord('incident');
grIncident.addQuery('sys_id',current.sys_id);
grIncident.query();
while(grIncident.next()){
grIncident.short_description = "Test from script action";
grIncident.setValue('assigned_to','');
grIncident.update();
}


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

Thank you,
Abhishek Gardade

Unfortunately, it does not work, even if it probably should...:(

Check if you are getting the correct record or not? Are you working in scoped application?

var grIncident = new GlideRecord('incident');
grIncident.addQuery('sys_id',current.sys_id);
grIncident.query();

gs.log("getRowCount:"+grIncident.getRowCount());\

Thanks,

Abhishek

Thank you,
Abhishek Gardade

Please check this....

Thank you,
Abhishek Gardade

Hello Milan,

Finally I got the issue and I have tested the functionality its working.

Here are my observations to find out the issue

1. Script action is running perfectly on time but due to another before business rule it is aborting the update.

2. To reproduce issue: comment out the line 5 and 6 as below: 

var rec = new GlideRecord(current.sys_class_name);

rec.get(current.sys_id);
rec.state = '9';
//rec.setValue('hold_reason','');
//rec.setValue('u_on_hold_reminder','');
rec.short_description = 'Test from script action';
rec.assigned_to = '';
rec.update(); 
gs.log('!!!MILAN CURRENT STATES AFTER SETTING THEM: ' + current.assigned_to.name + ' - ' + current.state + ' - ' + current.short_description);

keep any incident on hold, save it and then try to  changing state to on hold to in progress or another as you want and try to save. You will get below error (2 addInfoMessage):

invalid update()

On hold reminder datetime must be greater than current datetime.

3. So if you can check the business rule named "Story 130 Check On Hold Reminder".You just have added condtion on hold reminder is not empty and logic for validating date. 

RESOULTION: You can choose one of the solution.  I have modified the script action to just to achieve your need.  

1. Add more condition in business rule :"Story 130 Check On Hold Reminder" like incident state is not pending. use changesFrom, changesTo if needed.

2. Why you have created 2 different business rule? you can merge both business rules and if validation is successful then trigger event else abort update with alert.

3. Modify script action as I did already.

Let me know if anything else is needed.

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

Thank you,
Abhishek Gardade