Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

treycarroll
Giga Guru

We noticed a very odd issue yesterday when running a "no brainer" script to update items in a GlideRecord while next loop:

var gr = new GlideRecord("cmdb_ci");

  gr.addNotNullQuery('u_vulnerability_remediation_group');

  gr.query();

  while ( gr.next() ) {

            try {

                      gr.setValue('u_vulnerability_remediation_group',   '');

                      gr.update();

            } catch(e) {

                      gs.print(e.message);

            }

  }

I have used code like this for years in SNOW and it just works (err.. worked).   I have some examples just like this actually checked into source control!

Under Helsinki, the actual results of this script were "intriguing":   It deleted a single item and then exited the loop.  

After some tinkering I discovered that a function wrapper solved the problem.

//After wrapping the code in a IFFE, the loop continues to update items as expected.

(function() {

  var gr = new GlideRecord("cmdb_ci");

  gr.addNotNullQuery('u_vulnerability_remediation_group');

  gr.query();

  while ( gr.next() ) {

            try{

                      gr.setValue('u_vulnerability_remediation_group',   '');

                      gr.update();

            } catch(e) {

                      gs.print(e.message);

            }

  }

}());

1 Comment