How to get the all catalog variables variables into an array using a for loop ?

Krithika R
Tera Contributor

Hi All,
I have a record producer in that there are 10 client ids variables like client_id_1,client_id_2... I have to get all those variables and pass it into an array. As of now I am getting one variable at a time and pushing that, instead I need to check if it is empty or not and then push all the non-empty client_id into that array using a for loop. How to proceed with that?

As of now my run script looks like this, I have reduce the no. of line in the code so I thought of going to a for loop and pass only the non-empty values into that array. Can any one please suggest me how to do that?
find_real_file.png After the record producer is submitted it will create a record in case table.

1 REPLY 1

Martin Ivanov
Giga Sage
Giga Sage

Must be something like this

var grScReqItem = new GlideRecord('sc_req_item'); //this is specific req item, but you will use the current instead
if (grScReqItem.get('1677b4032f1411101dbdaf5df699b643')) {

    var result = [];

    for (var item in grScReqItem.variables){
        if(grScReqItem.variables[item]){
        gs.info (grScReqItem.variables[item]);
        result.push(grScReqItem.variables[item]);
        }
    }

}

Please mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022


Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024