In Server Script, is it possible to make the next Script work after insert() is committed?

Jaeik Lee
Mega Sage

I made Server Script that used GlideRecord.

In Script, After gr.insert() finished,  use that record to send SOAP message.

But sometimes error occured. SOAP message cannot reference inserted record.

there is example of Script :

 

var gr = new GlideRecord("table_name");

...

gr.insert();

...

sm = new sn_ws.SOAPMessageV2("SOAP i made");

...

 

Thank you for help.

 

4 REPLIES 4

Mark Manders
Mega Patron

What is the exact error?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

I think gr.insert() run async, so below script cannot get value of inserted record. but it was just my opinion, so i want clear answer.

You should be able to get the sys_id of the record you create and go from there. If you have the sys_id, the rest of the script should also work. You aren't sharing much and are not answering questions, which makes it difficult to answer.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

HS4
Tera Expert

Hi @Jaeik Lee ,

 

gr.insert() function must return a sys_id of inserted record. Store this sys_id in a variable and implement a check on this before making SOAP call.  

 

Do something like - 

 

var gr = new GlideRecord("table_name");

...

var record_id = gr.insert();

if(record_id){

sm = new sn_ws.SOAPMessageV2("SOAP i made");

...

}

 

If my answer helped you in any way, please then mark it as helpful or correct.

 

Thanks,