I am trying to iterate through an array of strings and insert the strings without inserting each more than once. But having a hard time...
grUser.addEncondedQuery(userEncodedQuery);
grUser.setLimit(10);
grUser.orderByDesc('name');
grUser.query();
while(grUser.next()) {
var userID = grUser.getValue('name');
userArr.push(userID);
}
userArr.forEach(myFunction);
function myFunction(item, index) {
gs.debug('user: ' + item + '; index: ' + index);
grInc.addQuery('short_description', 'short description');
grInc.addQuery('state', 7);
grInc.addQuery('assignment_group', '3cc3c7680b982300cac6c08393673a03');
grInc.query();
}
Index 0 is being used for all rows returned by the query instead of using index 0 for record 1; index1 for record2; index2 for record3; n...
Thought about using an if statement to check if the index has been used and if so to fetch the next one, but I am unsure as to how to set it up.
Something like....
while(grInc.next()) {
if(grInc.caller_id == item){
grInc.caller_id = userArr.item.hasNext();
}
grInc.close_notes = 'caller field populated through script 4';
grInc.update();
}
resulting in...
Background message, type:info, message: user: user1; index: 0
*** Script: INC0010047: State changed (Resolved->Closed),
Background message, type:info, message: user: user2; index: 1
*** Script: INC0010046: State changed (Resolved->Closed),
Background message, type:info, message: user: user3; index: 2
*** Script: INC0010045: State changed (Resolved->Closed),
Help me!