UI BUILDER: How to take the sys id from the newly created record with the created record data

fabrizio95360
Tera Expert

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
        }

 

 

1 ACCEPTED SOLUTION
7 REPLIES 7

Hasan6
ServiceNow Employee

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

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

ersureshbe
Giga Sage

Hi, You should use glideaAjax and send the ticket number in the GlideAjax function and get the sys_id details.

Regards,
Suresh.