Script Action to add work notes to Change Request?

Tom Siegel
Kilo Guru

I have a question on the best way to create work notes on a Change request based upon a Run Script Action in the Change workflow. 

This is the code for the Change Work Flow Run Script Action 

if (workflow.scratchpad.sendmail===undefined){
	var gr = new GlideRecord("task_service_offering");
gr.addQuery("task", current.sys_id);
gr.addQuery("u_type", "impacted");
gr.query();
while (gr.next()) {
    gs.eventQueue("impacted.so.notification", gr);
}
workflow.scratchpad.sendmail="true";
}

As you can see the script above, there is an event created called "impacted.so.notification" that passes a glide record as parm 1. The ask is to create a work note on the current Change for every email that is generated by this Run Script Action. My question is what is the proper way from a platform architecture perspective on how to achieve this. Since it appears that a "Script Action" can be fired from an event, having not worked with them before, I was wondering if I should head down that path?

Thanks - Tom

1 ACCEPTED SOLUTION

Hi,

It may be that the current object is only updated once per run script.

With that said, you can create a separate loop like:

if (workflow.scratchpad.sendmail===undefined){
count = 0;
	var gr = new GlideRecord("task_service_offering");
gr.addQuery("task", current.sys_id);
gr.addQuery("u_type", "impacted");
gr.query();
while (gr.next()) {
    gs.eventQueue("impacted.so.notification", gr);
    count = count + 1;
}
for (var i = 0; i < count; i++) {
var gr2 = new GlideRecord('current_table_name');
gr2.get(current.sys_id);
gr2.work_notes = "Hello World!";
gr2.update();
}
workflow.scratchpad.sendmail="true";
}

So this is a round about way to get the current record updated multiple times without using current.update();

Just replace current_table_name with the table name this workflow is running on.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

6 REPLIES 6

ServiceNerd
Giga Guru
Giga Guru

Hi,

Thanks for the video 🙂

I don't know if script actions apply here? This was talking about a Run Script activity in a workflow to trigger an event to fire a notification. You may have been searching for specific keywords to post your various videos?

In any case, thanks anyway!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!