In Server Script, is it possible to make the next Script work after insert() is committed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 12:04 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 01:26 AM
What is the exact error?
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 01:32 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 04:15 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2024 03:50 AM
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,