Work notes for multiple records update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 09:51 PM
Hello,
This is kind of weird, I have two tables
Table1 and Table2
Table2 is under related list of Table1
My BR runs when Table1 is updated and STATE field has value Closed
and this queries the Table2 and gets all the records related to Table1 and updates the WORK NOTES as CLOSED
But here:
when Table2 has 5 records related to Table1 - The WORK NOTES on Table2 is updating for only one record - its not showing the message form other 4 records, what would be the issue here?
BR:
RUNS ON TABLE1
var gr = new GlideRecord('Table2');
gr.addQuery('Field1', current.sys_id); //relating to Table1
gr.query();
while(gr.next())
{
// Here if i have 5 records - the worknotes is updating for only 1 record
gr.state = Closed;
gr.work_notes = "The State is changed to Closed because the Table1 is changed to Closed";
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 10:02 PM
Hi,
I dont see anything wrong in the code.
Check whats the rowcount the query is returning .
var gr = new GlideRecord('Table2');
gr.addQuery('Field1', current.sys_id); //relating to Table1
gr.query();
var count = gr.getRowCount();
gs.addInfoMessage(count);
Run this code and see the value of count.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 10:03 PM
Hi,
You might try the updateMultiple() method as referred here. Please try the below script and let me know.
var gr = new GlideRecord('Table2');
gr.addQuery('Field1', current.sys_id); //relating to Table1
gr.query();
gr.setValue('state', 'Closed'); //Pass correct state choice value of Closed
gr.work_notes = "The State is changed to Closed because the Table1 is changed to Closed";
gr.updateMultiple();
I hope this helps.Please mark correct/helpful based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 10:30 PM
Thank you Guys for the quick reply,
Sneha - The row count is good.
Amlan - I tried putting gr.updateMultiple(); even this gave me the same result.
Thanks,
Red
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 10:44 PM
Hi,
It should work. I have just tested in my personal instance and the same logic is working fine. Please try the below script and make sure that the State choice value of 'Closed' is properly passed in the script.
var gr = new GlideRecord('Table2');
gr.addQuery('Field1', 'current.sys_id'); //relating to Table1
gr.query();
gr.setValue('state', 'Closed'); //Pass correct state choice value of Closed
gr.setValue('work_notes', "The State is changed to Closed because the Table1 is changed to Closed");
gr.updateMultiple();
I hope this helps.Please mark correct/helpful based on impact