Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
ServiceNow JavaScript Retrieving/inserting string items in array to field in different rows

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!