Get RITM number through sys_id

Dafni Tsipra
Giga Contributor

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!

1 ACCEPTED SOLUTION

@Dafni Tsipra 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

10 REPLIES 10

You are welcome.

Please remember to mark responses as helpful as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Mark Roethof
Tera Patron
Tera Patron

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:

find_real_file.png

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

LinkedIn

Yes you are right! but on my code is correct with 'p' not 'P' ..though copy paste by accident I changed it.

Mike Patel
Tera Sage

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' ) ;

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.