how to populate the condition field in the filter using scripting?

mouli7
Tera Contributor

Hi all,

my third party is providing me the list of application services and its blackout values in the below format

var reqData = {
"ID": "8611",
"Details": "INPAT:SBBW_Monday_14:16_R0",
"Recurrence": "Monthly",
"StartTime": "06/05/2024 14:00:06",
"EndTime": "06/05/2024 16:00:16",
"MType": "Day of the month",
"Application": [{
"AppName": "DI_metal_app_service"
},
{
"AppName": "DI_metal_app_service1"
},
{
"AppName": "DI_metal_app_service2"
}
]
}

how to populate the application services name in the below format in the blackout schedule

mouli7_0-1715150765411.png

 

I have tried the below code but it does not help me

 

var conditiona = "";
var gr = new GlideRecord('cmn_schedule_blackout');
gr.addQuery('sys_id', 'e518327987b9829c49aa0d030cbb350c');
gr.query();
if (gr.next()) {

gs.info('dsssdggg:,.........................' + gr.source);
var arrayUtil = new global.ArrayUtil();
for (var i = 0; i < reqData.Application.length; i++) {
var appName = reqData.Application[i].AppName;
gs.info('appName..........' + appName);
if (conditiona) {
conditiona += "OR";
}
conditiona += '("ref_cmdb_ci_service_auto.name="' + appName + ' ")' ;

}

}
gr.condition = "(" +conditiona + ")";
gr.update();


please provide me a solution if possible.

1 ACCEPTED SOLUTION

By using the "IN" operator you're able to execute a much more efficient query. OR conditions in SQL are much slower and impact instance performance 

View solution in original post

5 REPLIES 5

By using the "IN" operator you're able to execute a much more efficient query. OR conditions in SQL are much slower and impact instance performance