- 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 06:57 AM
Hi,
please share your complete script
You must be creating 2nd RITM from workflow run script; then trying to use it later
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 07:05 AM
Here is the code before the above
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('a specific sys_id', 1);
var mySysID = gs.generateGUID();
item.setNewGuidValue(mySysID);
workflow.scratchpad.RITM_SYSID = mySysID;
cart.setVariable(item, 'opened_by', current.updated_by);
....and a banch of setvariable
var rc = cart.placeOrder();
- 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 07:49 AM
Thank you so much Ankur!