Getting new sys_id from a UI Builder Create Data Resource execute call

SG17
Tera Expert

I have a Create Data Resource (create_new_test_record_from_button_click) within UI Builder and call .execute() on it with my template fields. Is there a way to get the sys_id of the newly created record?

 

api.data.create_new_test_record_from_button_click.execute({
     "table": "x_g_test_table",
     "templateFields": templateFields,
     "useSetDisplayValue": false
});

 

The api of the execute function doesn't seem to return anything.

https://docs.servicenow.com/bundle/tokyo-api-reference/page/app-store/dev_portal/API_reference/api/c...

 

Regards

3 REPLIES 3

Marco0o1
Tera Sage

Hi @SG17 ,

Is look that you need to return your sys_id when you are declaring your function 'create_new_test_record_from_button_click.execute' on your script, I imagine that you have a record.insert() in your functions, you can do something like:

create_new_test_record_from_button_click.execute = function(){
.
. //code
.
return record.insert()
}

Then when you are executing your UI action store the sys_id that is returned from your function like:

 

var returnedSysID = api.data.create_new_test_record_from_button_click.execute({
     "table": "x_g_test_table",
     "templateFields": templateFields,
     "useSetDisplayValue": false
});  


// returnedSysID will have the sys_id

Is similar that the Doc you provide like this:

Marco0o1_0-1697226610679.png

 

If you dont declare nothing to be returned from you function, won't return anything for this you must declare and store in a variable when you execute your code in the same way. 

Thanks @Marco0o1. The execute() function is on an OOB Create Data Resource so I can't control what it returns and it doesn't return anything per the API I linked to. It's not ideal but I could check the table for the last inserted record.  

Nootan Bhat
Kilo Sage

Hi @SG17,

UI builder api execute will not return the values.

So one approach that you can use is to call the REST apis from the Client code. Which will give the response result. 

Refer https://developer.servicenow.com/dev.do#!/reference/api/utah/client/helpersAPI#helpers-snHttp_S_O

use the rest API explorer to understand which is best fit api for you.

Ex: you can use POST method URL could be like: /api/now/table/{tableName} 

 

Please accept the reply if it resolved your issue.

Thanks

Nootan