Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

I am trying to create a background script for closing a change, for which workflow has broken

sunthosh
Tera Contributor

Hello

I am trying to create a background script for closing a change, for which workflow has broken. Advise on it please.

function getUserRegion() {

  var u = gs.getnumber();

  var gr = new GlideRecord('change_request');

  gr.addQuery('CHG00046',u);

  gr.query();

  while (gr.next()) {

          gr.u_stage= 7;

          gr.update();

  }      

1 ACCEPTED SOLUTION

If you need to change the state, then update the script to use the state field instead.



var gr = new GlideRecord('change_request');


    if (gr.get('number', 'CHG00046')) {


          gr.state= 7;


          gr.update();


View solution in original post

14 REPLIES 14

Chuck Tomasi
Tera Patron

Hi Hari,



There's no method for gs called 'getnumber'. Try this instead.



function getUserRegion() {



  var gr = new GlideRecord('change_request');


    if (gr.get('number', 'CHG00046')) {


          gr.u_stage= 7;


          gr.update();


  }      


function getUserRegion() - is this name correct.



i need to access change_request table.


chrissquires1
Tera Guru

This line might be your issue:


gr.addQuery('CHG00046',u);



Change it to gr.addQuery('number', 'CHG00046'); and it should work. Your change request number looks to be a little short.   I'm used to seeing seven digits, and this one is five.


You can either hard-code the number, if you're using a fix script, or programmatically grab the record number using something like var u = current.number; but I don't think var u = gs.getnumber(); is doing anything for you.



(Beat me to it Chuck )


function getUserRegion()   /* IS THIS CORRECT, AS I NEED TO ACCESS CHANGE RECORD */


{



  var gr = new GlideRecord('change_request');


  gr.addQuery('number', 'CHG00046');


  gr.query();


  while (gr.next()) {


          gr.u_stage= 7;


          gr.update();


  }