Wait for GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 06:10 AM
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
- Labels:
-
Knowledge Management
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 06:29 AM
You can use this logic:
if(gr1.hasNext())
{
//CONTINUE
}
else
{
var gr2= new GlideRecord(<Table name>);
if(gr2.hasNext())
{
//CONTINUE
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 07:13 AM
didn't work