Retrieve special instructions on request via script

Brian Hofmeiste
Kilo Guru

Is there a way to grab special instructions from the request container and apply it to comments of the requested item? For example:

 

current.comments = current.parent_request.special_instructions 

thanks! 

1 ACCEPTED SOLUTION

You shouldn't ever need to do a GR on sc_req_item to retrieve the current record, because the current record is what the workflow is running on.  I added a one line Run Script activity as the first activity following Begin, and this worked for me:

current.comments.setJournalEntry(current.request.special_instructions);

Just using current.comments = didn't work in this case, but I knew the special_instructions were getting picked up correctly by adding a logging line

workflow.info('SI ' + current.request.special_instructions);

then viewing the log via the Log tab on the Workflow Context Related Link on the RITM.  The workflow runs on the sc_req_item table when the record is created, which is after the sc_request (REQ) record is created, so I've never experienced any trouble with retrieving or updating any fields on the RITM or REQ records right off the bat.

 

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Hi Brian,

 

Special instructions is a field on the sc_request table, so from the sc_req_item it would be more like:

 

current.comments = current.request.special_instructions;

 

 

 

Oh sweet so current.request allows me to access the parent request container? I couldn’t figure that out.  I will try when I get home.  Thanks?

 

Brian

OK I just tried this but it doesnt appear to be working.  I'm adding this to the workflow advanced script area - where do see error messages in the processing?  I'm googling around but havent found logs or error codes anywhere.  Thanks!

Brian Hofmeiste
Kilo Guru

Here is the script I used to grab the special instructions collected at the cart - and dropped them in to the comments of the requested item.  Then I was able to grab this and place the information on down stream tasks. 

var gr= new GlideRecord("sc_req_item");
gr.get(current.sys_id);
gr.comments.setJournalEntry(current.request.special_instructions);
gr.update();

 

At first I was using the "Run Script" core activity in the workflow editor.  For some reason "current" was returning blank text when using this script.  Perhaps the requested item had not yet been created?  I removed the "run script" activity and placed my script in the very first approval activity and it started working.  Would love feedback from someone on why "current" would not work at the beginning of the workflow.