How to update a field of multiple records on the basis some records in array;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 04:45 AM
How to update a field of multiple records on the basis some records in array.
Scenario: There is array X and need to update a field of multiple records by inserting element from array X.
Example:
var x = 0;
var x2 = 3;
X = [ "xyz", "abc", "def", "mno" ];
for (x; x<=x2; x++) {
var obj6 = new GlideRecord('incident');
obj6.addEncodedQuery('active=true^caller_id=46d44a23a9fe19810012d100cca80666');
obj6.query();
while(obj6.next())
{
obj6.short_description = X;
obj6.update();
}
}
Expected output: As per the above script, the short description of 4 Incident records should be updated as
xyz in 1st Incident, abc in 2nd incident, def in 3rd incident and mno in 4th incident.
I used above code but it is not working properly.
Any idea how to achieve this sol?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 05:19 AM
Hi,
Thanks for reply.
This script is not working properly.
It is not updating the current record.
It is creating new record and there short desc is updating.
Please check in your instance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 05:40 AM
Please try below.
var X = [ "xyz", "abc", "def", "mno" ];
var flag = 0;
var obj6 = new GlideRecord('incident');
obj6.addEncodedQuery('active=true^caller_id=46d44a23a9fe19810012d100cca80666');
obj6.setLimit(X.toString().split(",").length); // set limit of total records to query, matching array
obj6.query();
while(obj6.next())
{
obj6.short_description = x[flag];
obj6.update();
flag++
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 06:30 AM
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-22-2022 06:34 AM
Thanks, please mark it correct and close the thread so that it benefits future readers.
Thanks
Harshad