- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2019 04:50 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2019 11:11 PM
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
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 12:07 AM
Hi Abhishek,
thanks for your advice, the thing is that the solution with script action should just work as I have modified the code (please see below) ang according to log I get the right gs.info data...which means the event gets fired and the script action reacts to it...
The only thing I see aproblem with is that thew current.update() part does not just work and I have no idea why....
Many thanks. Milan
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 12:28 AM
Hell MIlan,
Don't use function, directly add code and Are you working in which scope?
//current.state = '9';
current.short_description = "Test from script action";
current.setValue('assigned_to','');
current.update();
gs.info('!!!MILAN' + current.assigned_to + current.state + current.short_description);
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 01:08 AM
Or you can create gliderecord in script action:
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
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2019 10:07 AM
Hello Milan,
1. Modified your script action as below;
2. Modified your business rule:
I have tested the functionality its working.
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-14-2019 05:13 AM
Hi,
Why can't you update your logic within a BR itself. Why do you require a Script action for this requirement?
Regards,
Shloke
Regards,
Shloke