UI Action to get field value from sysID

mrunalnikhi
Tera Contributor

I am trying to get product id from current form on UI Action script, So for that I am getting sys_id using selecting the record which I am getting as 

var keys = g_list.getChecked();
and using following below that to fetch the product id for that record, 
var gr = new GlideRecord('sn_ind_tmt_orm_c360_products');
gr.addQuery('sys_id', keys); // 'keys' contains the sys_id value
gr.query();

if (gr.next()) {
    // Process the record
    var displayValue = gr.u_service_id;
alert('displayValue'+ displayValue);
    // Additional processing
}
 
but I am not getting anything there. Please help.
This product Id needs to be send to Script include further.
3 REPLIES 3

Gangadhar Ravi
Giga Sage
Giga Sage

Hi @mrunalnikhi 

 

@please try this 

 

// Get the selected sys_id(s)
var keys = g_list.getChecked();

// Check if multiple sys_ids are selected
var sysIdsArray = keys.split(',');

// Initialize GlideRecord for 'sn_ind_tmt_orm_c360_products'
var gr = new GlideRecord('sn_ind_tmt_orm_c360_products');

// If there's more than one sys_id, use addQuery with 'IN'
if (sysIdsArray.length > 1) {
gr.addQuery('sys_id', 'IN', sysIdsArray);
} else {
// Otherwise, query for the single sys_id
gr.addQuery('sys_id', keys);
}

// Query the table
gr.query();

while (gr.next()) {
var displayValue = gr.u_service_id;
alert('displayValue: ' + displayValue);
}

 

Please mark my answer correct and helpful if this works for you.

mrunalnikhi
Tera Contributor

Thanks for the solution, but still it is not working

 

Mani A
Tera Guru

@mrunalnikhi  if you want current form field data..then simply use g_form.getValue('u_service_id') and write GlideAjax logic

 

otherwise if you go with ur script logic and .directly call script include by passing keys In function parameter

 

  1. But in script include just change addQuery('sy_id','IN',keys) and use while loop