The CreatorCon Call for Content is officially open! Get started here.

How to update a field of multiple records on the basis some records in array;

Not applicable
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?



8 REPLIES 8

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.

Harshad Wagh
Tera Guru

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++
	}
}

Thanks @Harshad Wagh . it's working

Thanks, please mark it correct and close the thread so that it benefits future readers.

Thanks

Harshad