Getting new sys_id from a UI Builder Create Data Resource execute call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 10:01 AM
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.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2023 12:51 PM
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2023 04:52 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 03:27 AM - edited 10-20-2023 03:31 AM
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