Add worknotes with workflow Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2015 11:52 PM
Hi all,
We have already implemented a SLA workflow, that trigger events and send notifications once incidents reach one percentage. 30,60,80,90. No problem with that.
The issue is that I need to add a worknote to the incident every time that we are sending the notification and for that I just add there some run scripts.
I try many things there. For instance, current. work_notes = "Test"; But none of them updates the ticket, even I'm able to see that logs are ok and same code works well using schedule job.
Do I need to add something there, in order to update the incident?
Many thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 04:16 AM
Could you post the code from the activity?
I'm thinking that this is running on the SLA table so the current.work_notes is incorrect. You would need to get the task from the SLA record and update it via script.
R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 04:24 AM
Hi Russell,
Thanks for your answer. I have already fixed the problem. Bellow code is working fine.
But, I read somewhere that is not good practice to use update() command at workflows
var gr = new GlideRecord('incident');
gr.get(current.task.sys_id);
gr.work_notes = 'Be informed that incident SOX SLA elapsed time is 30 days. ';
gr.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-05-2015 06:33 AM
Below should work which is only a slight alteration to what you did. But you are correct using update() can cause issue, but only if you are updating a record that the workflow will interact with. So updating the incident will cause the SLA BR's to run which could cause the workflow to run again which could put you into a loop. In this case I think you would be ok.
Just a thought you mite want your code to check to see if it got a record.
var gr = new GlideRecord("incident");
if(gr.get(current.getValue("task")){
gr.setValue("work_notes", "Test");
gr.update();
}