server side script

admin11345_
Tera Contributor

1) record a query with some specifications and
2) open that form(I mean record).
3) I need to write the server side script for getting the record's sys_id which I have opened in step 2  and then query few actions
how to obtain record's sys_id through server side script  in ATF ?

1 REPLY 1

kamlesh13
Tera Contributor

Hey @admin11345_ ,

 

Please use below code and make needful changes in it,

 

var tableName = 'your_table_name'; // Replace with the actual table name
var conditionField = 'field_name'; // Optional, add field name if needed
var conditionValue = 'field_value'; // Optional, add field value if needed

var gr = new GlideRecord(tableName);
if (conditionField) {
    gr.addQuery(conditionField, conditionValue);
}
gr.query();

if (gr.next()) {
    var sysId = gr.getValue('sys_id'); // Get the sys_id directly
    gs.info('Record sys_id: ' + sysId);
} else {
    gs.info('No matching records found.');
}
gr.close();

 

Regards,

Kamlesh