- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 06:54 AM
Hello everyone!
I have a workflow in which a RITM2 is generated and I store its number to a workflow.scratchpad variable.
On the same script but later I want to write this RITM2's number to a work note of the current RITM1 but it doesn't appear.
I used gs.addInfoMessage and it shows RITM2's number correct but still work notes are not updated correct.
Here is the code:
//GET RITM2'S NUMBER
var childReqIt = new GlideRecord('sc_req_item');
childReqIt.addQuery('sys_id', workflow.scratchpad.RITM_SYSID);
childReqIt.query();
gs.addInfoMessage('RITM_SYSID ' + workflow.scratchpad.RITM_SYSID);
while (childReqIt.next()) {
gs.addInfoMessage( childReqIt.number);
}
//WRITE WORK NOTES ON RITM1
var parentReqIt = new GlideRecord('sc_req_item');
parentReqIt.addQuery('sys_id', current.sys_id);
parentReqIt.query();
while (parentReqIt.next()) {
parentReqIt.work_notes = (childReqIt.number + 'created' ) ;
ParentReqIt.update();
}
I would really appreciate any help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 07:19 AM
So it should be like this
// your original code here
var rc = cart.placeOrder(); // this gives you REQ record
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request.number', rc.number);
ritm.query();
if(ritm.next()){
workflow.scratchpad.ritmNumber = ritm.number;
}
/WRITE WORK NOTES ON RITM1
var parentReqIt = new GlideRecord('sc_req_item');
parentReqIt.addQuery('sys_id', current.sys_id);
parentReqIt.query();
if(parentReqIt.next()) {
parentReqIt.work_notes = workflow.scratchpad.ritmNumber + ' created' ;
ParentReqIt.update();
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 08:00 AM
You are welcome.
Please remember to mark responses as helpful as well.
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 06:57 AM
Hi there,
Try to use an editor, this will provide you with valuable information.
For example, without even looking at the logic of your script, I instantly see at least:
Notice the color code difference. So at least this is an issue. Maybe there's more, though this at least. parentReqIt vs ParentReqIt
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 07:07 AM
Yes you are right! but on my code is correct with 'p' not 'P' ..though copy paste by accident I changed it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 07:10 AM
change
gs.addInfoMessage( childReqIt.number);
to
workflow.scratchpad.RITM_NUMBER = childReqIt.number;
change
parentReqIt.work_notes = (childReqIt.number + 'created' ) ;
to
parentReqIt.work_notes = (workflow.scratchpad.RITM_NUMBER + 'created' ) ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-06-2020 07:24 AM
I tried it but it isn't working.
Using gs.addInfoMessage before and after the while (childReqIt.next()) it seems that isn't inserting in while section.