Script action reacting to event having access to current object but not updating fields

Milan13
Giga Expert

Hello,

I have a problem with script action which reacts to appropriate event, has access and can set up the "current" object, but does not update fields.

I have added some gs.log statements which show the code works partially apart of the current.update() part.

Can anyone please advise?

Many thanks,

Milan

My script action:

setFields();

function setFields() {

gs.info('!!!MILAN CURRENT STATES BEFORE SETTING THEM: ' + current.assigned_to + ' - ' + current.state + ' - ' + current.short_description);
current.state = '9';
current.short_description = 'Test from script action';
current.assigned_to = '';
gs.info('!!!MILAN CURRENT STATES AFTER SETTING THEM: ' + current.assigned_to + ' - ' + current.state + ' - ' + current.short_description);

try {

current.update();
}
catch(err) {

gs.error("UPDATE ERROR: " + err);

}

Log screen shot (not showing any update error so far..):

find_real_file.png

 

1 ACCEPTED SOLUTION

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

View solution in original post

15 REPLIES 15

No it does not work, nor does it set the values before update (according to log).

Thanks a anyway.

Milan

AbhishekGardade
Giga Sage

Hello Milan,

Please check the domain of script action if you are working in domain separated instance.

Script Action must be in a global domain in order to run.

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

Thank you,
Abhishek Gardade

I guess the script action is in Global domain...not sure but I would say I did this task before my instance upgrade in June or July this year I guess and I think it worked, I have Madrid, but not sure..thanks, Milan

 

find_real_file.png

Can you share script from where you are calling the eventQueue?

Thanks,

Abhishek

Thank you,
Abhishek Gardade

I can but I do not think its the reason as according to log it gets fired properly.

Business Rule: 

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


gs.eventQueueScheduled('on.hold.reminder', current, 'parm1', 'parm2', current.u_on_hold_reminder);

})(current, previous);