The CreatorCon Call for Content is officially open! Get started here.

In a workflow, how to pull work notes from one catalog task to another?

selenasmith
Kilo Contributor

I'm working on a (relatively) simple workflow which creates 2 catalog tasks:

1.   First task, send to support group manager for approval and comments in the "work notes" field.

2.   Second task to server admins for action

The second task needs to include the work notes from the first field.   What's a simple way to accomplish this?

Thanks,
Selena Smith

1 ACCEPTED SOLUTION

Ahhh... See that is the problem, I was assuming this is on the sc_req_item all the way. Change your script to this, hopefully it will work now.



task.work_notes=pullComments();


function pullComments(){


  var comments=[];


  var gr= new GlideRecord("sc_task");


  gr.addQuery("request",current.getValue("sys_id"));


  gr.query();


  while(gr.next()){


  comments.push(gr.work_notes.getJournalEntry(-1));


  }


  return comments.join();


}


View solution in original post

30 REPLIES 30

sourabhd87
Tera Contributor

Hi Selena,


workflow.scratchpad.wknotes = task.work_notes; should be added in the task from which work notes needs to be copied.


You can retrieve the scratchpad variable in any task that follows simply by mentioning:


var abc = workflow.scratchpad.wknotes;



Using the Workflow Scratchpad - ServiceNow Wiki


Let me know if that works.



Kind regards,


Sourabh D


Abhinay Erra
Giga Sage

What do you see form the logs that you placed in the script?


Abhinay Erra
Giga Sage

Did you try to see the logs to know if the script is working properly or not?


I'm not sure where the logs are located


If you have not changed, first change your script in the task activity to   this


task.work_notes=pullComments();


function pullComments(){


  var comments=[];


  var gr= new GlideRecord("sc_task");


  gr.addQuery("request_item",current.getValue("sys_id"));


  gr.query();


  while(gr.next()){


  gs.log("From workflow "+ gr.number);


  comments.push(gr.work_notes.getJournalEntry(-1));


  gs.log("From workflow "+ gr.work_notes.getJournalEntry(-1));


  }


  gs.log("From workflow final return "+comments.join());


  return comments.join();


}



Then publish your workflow, then order that item again and close the task1 so that task2 is created. Now go to the logs as shown below



Type Script log in the navigator and open the module as shown below and add a filter condition which says Message contains From workflow.


find_real_file.png