- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 12:47 AM
Hi Developer,
I'm creating a record in a table via the client script using the created record data method, and I need the sys_id of the newly created record, is there a way to get it in the client script?
this is my code in client script:
function handler({api, event, helpers, imports}) {
let objSelectedRecords = api.state.jsonSelectedRecords; //JSON.parse(api.state.jsonSelectedRecords);
let objFormValues = JSON.parse(api.state.jsonFormValue);
if (objFormValues.bulk_case) {
let tableBulkCase = 'x_nttdi_gosign_con_gosign_bulk_case';
let fieldsBulkCase = '';
fieldsBulkCase += `source_table=${objSelectedRecords.table}^`;
fieldsBulkCase += `source_record=${objSelectedRecords.sys_ids[0]}^`;
fieldsBulkCase += `case_source=${objSelectedRecords.sys_id_source}^`;
for (const propertyBulk in objFormValues) {
fieldsBulkCase += `${propertyBulk}=${objFormValues[propertyBulk].value}^`;
}
fieldsBulkCase = fieldsBulkCase.slice(0, -1);
api.data.create_record_bulk_case.execute({
table: tableBulkCase,
templateFields: fieldsBulkCase,
useSetDisplayValue: false
});
//I want to get the sys_id of created record
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 06:55 AM
I used this approach to get the sys_id: https://www.servicenow.com/community/next-experience-articles/how-to-create-a-record-and-immediately...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 07:59 AM
Hi Fabrizio,
Few alternatives you can try:
Create a transform data broker return the sysid there.
Or from the client script, make a rest table api call and use the parse the response to get the sys id.
Hope this helps
Best
Hasan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 03:19 AM
Hi @Hasan6 ,
can you maybe elaborate more on this topic? I have similar issue. I'm creating new record via my button and build in SAVE data resource. Record is created but I'm unable to figure it out how do I get the sysID of this new record in ui builder as I need to work with that sysid later.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 06:55 AM
I used this approach to get the sys_id: https://www.servicenow.com/community/next-experience-articles/how-to-create-a-record-and-immediately...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-18-2023 03:38 AM
Hi, You should use glideaAjax and send the ticket number in the GlideAjax function and get the sys_id details.
Suresh.