How to get the all catalog variables variables into an array using a for loop ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2022 12:26 AM
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? After the record producer is submitted it will create a record in case table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2022 12:41 AM
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