Getting display values from sys ids

servicenow14710
Tera Expert

Hello developers,

 

I have tricky implementation of getting sys ids in an array. after glide record i could query these sys ids and store in array. Now from this array i need to get their desplay values to send to notifications, Tried using getDisplayValue on this array but didnt work, , Any help is appreciated, Thanks!

1 ACCEPTED SOLUTION

Krushna R Birla
Kilo Sage

Hi @servicenow14710 

 

You can use below logic for your requirement,

Example:-

var sysIdsArray = ['sys_id1', 'sys_id2', 'sys_id3'];  //Your array containing sys_id
var resultArray = [];

// Loop through each sys_id in the array
for (var i = 0; i < sysIdsArray.length; i++) {
    var gr = new GlideRecord('your_table_name'); // Replace 'your_table_name' with the appropriate table name
    gr.addQuery('sys_id', sysIdsArray[i]);
    gr.query();
    if (gr.next()) {
        resultArray.push(gr.<'your_field_name'>.getDisplayValue());
    }
}

// Now you have an array of display values corresponding to the sys_ids
// You can use resultArray to send notifications or perform any other operations
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

View solution in original post

3 REPLIES 3

Sagar Pagar
Tera Patron

Hi @servicenow14710,

 

Can you share your scripts here?

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Krushna R Birla
Kilo Sage

Hi @servicenow14710 

 

You can use below logic for your requirement,

Example:-

var sysIdsArray = ['sys_id1', 'sys_id2', 'sys_id3'];  //Your array containing sys_id
var resultArray = [];

// Loop through each sys_id in the array
for (var i = 0; i < sysIdsArray.length; i++) {
    var gr = new GlideRecord('your_table_name'); // Replace 'your_table_name' with the appropriate table name
    gr.addQuery('sys_id', sysIdsArray[i]);
    gr.query();
    if (gr.next()) {
        resultArray.push(gr.<'your_field_name'>.getDisplayValue());
    }
}

// Now you have an array of display values corresponding to the sys_ids
// You can use resultArray to send notifications or perform any other operations
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

Sohail Khilji
Kilo Patron
Kilo Patron

Hi @servicenow14710 ,

 

lets say,,

var sysIds = ['sys_id_1', 'sys_id_2', 'sys_id_3'];
var displayValues = [];
sysIds.forEach(function(sysId) {

    var gr = new GlideRecord('your_table_name');
    if (gr.get(sysId)) {
        var displayValue = gr.getDisplayValue();
        displayValues.push(displayValue);
    }
});

// Now you have an array of display values to use in notifications or any other logic

☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect