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.

Wait for GlideRecord

nakamura2
Kilo Explorer

Hi ServiceNow community,

I have searched a lot and didnt find anything about this, but i want to know how can i wait for a GlideRecord to finish before running another function:

CLIENT SCRIPT

c.data.processo = '555555'

c.server.update().then(function(){

console.log(c.data.id);

//$rootScope.$broadcast('consultar', c.data.id);

})

SERVER SCRIPT

if (input.processo){

var gr = new GlideRecord('x_jam_processos_processos')

      gr.addQuery("u_numero_unico", input.processo)

      gr.query();

      while (gr.next()){

              data.id = gr.sys_id;

      }

}

c.data.id returns an empty object ({}), and i cant do a while timeout without locking my widget.

It should working because im waiting for a promise, but the variable is empty.

By the way this is in a widget from service portal.

Sorry for bad english , please help

2 REPLIES 2

Shusovit
Mega Expert

You can use this logic:



if(gr1.hasNext())


{


//CONTINUE



}


else


{


                  var gr2= new GlideRecord(<Table name>);


                 


                  if(gr2.hasNext())


                  {


                  //CONTINUE


                  }




}


didn't work