updateMultiple() is not working while using in fix script

Shweta Mayekar
Tera Contributor

Hello,

 

I have to update multiple records in scoped app but when i tried to update record using updateMultiple(), it is not working.

Script : 

var gr = new GlideRecord('x_hclan_gbs_financ_p2p_request');
gr.addEncodedQuery("numberINP2P6688772,P2P6689407,P2P6689784,P2P6690341,P2P6690659");
gr.query();
gr.state = 7;
gr.work_notes="We are closing this ticket as per the request through the story : STRY0163997";
gr.updateMultiple();

 

Please suggest what is wrong in the script.

Thanks in advance

1 ACCEPTED SOLUTION

prashanth2
Kilo Guru

Hey, I think the updateMultiple does not work with Journal entries.

you will have to loop through and update each record.

updateMultiple()
Updates each GlideRecord in a stated query with a specified set of changes.
This method does not support adding multiple journal entries.

Note: To ensure expected results, use the setValue() method instead of direct assignments. That is, use gr.setValue('<field_name>', '4')); instead of gr.<field_name> = 4.
Note: Do not use this method with the chooseWindow() or setLimit() methods when working with large tables.
This method sets new values and does not clear existing values. To clear an existing value, use the setValue() method and set the field to null.

https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideRecordScope...

 

If this helps, please mark the answer correct/helpful.

View solution in original post

6 REPLIES 6

Mike_R
Kilo Patron
Kilo Patron

Can you add this line after gr.query() to see if it's even returning the correct number of records

gs.info(gr.getRowCount());

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Try below

var gr = new GlideRecord('x_hclan_gbs_financ_p2p_request');
gr.addEncodedQuery("numberINP2P6688772,P2P6689407,P2P6689784,P2P6690341,P2P6690659");
gr.query();
while(gr.next())
{
gr.state = 7;
gr.work_notes="We are closing this ticket as per the request through the story : STRY0163997";
gr.updateMultiple();
}

Please note it is always advisable to use setWorkflow(false) as well but it will not update work notes because work notes is a journal field but try in lower instance and see impact of script without using setWorkflow(false).

Please hit like and mark my response as correct if that helps
Regards,
Musab

Hello Musab,

 

I want to update worknote also.

Try this in lower instance, I have not used setWorkflow(false) so first see if it has any acceptable impact if not then you can run this, Also as I said earlier you need different approach to update worknotes if you use setWorkflow(false) but I'm unable to find any thread on that so as of now take this.

var gr = new GlideRecord('x_hclan_gbs_financ_p2p_request');
gr.addEncodedQuery("numberINP2P6688772,P2P6689407,P2P6689784,P2P6690341,P2P6690659");
gr.query();
while(gr.next())
{
gr.state = 7;
gr.work_notes="We are closing this ticket as per the request through the story : STRY0163997";
gr.update();
}
Please hit like and mark my response as correct if that helps
Regards,
Musab