Update condition builder via script

Edwin Fuller
Tera Guru

I have a catalog item where users select multiple applications and multiple locations. Upon submitting the catalog item a record is created within the "sys_notif_subscription" table. I need to update the condition builder for the created record with or statements for all of the applications the user selects and all of the locations the user selects.

For example the users selects "ServiceNow" and "Microsoft" as applications and "New York" and "Kansas" as locations 

The condition should reflect: u_affected_ci is ServiceNow OR u_affected_ci is Microsoft or u_offices_locations_impacted is New York OR u_offices_locations_impacted  is Kansas

Please see screen shot below and my script in the current versions. Any help is greatly needed.

Script

var subscription = new GlideRecord('sys_notif_subscription');
subscription.initialize();
subscription.name = current.variables.name;
subscription.user = current.variables.requested_for;
subscription.notification = current.variables.notification;

if(current.variables.application != '' || current.variables.u_offices_locations_impacted != ''){
subscription.condition = '^u_affected_ci = current.variables.application';
}

var subscriptionID = subscription.insert();

Screen Shot

find_real_file.png

 

1 ACCEPTED SOLUTION

Okay, that's quite a bit trickier.  Try this in place of your 'if' condition in your script above.

if(current.variables.application != '' || current.variables.u_offices_locations_impacted != ''){
    // Initialize the query string
    subscription.condition = '';
    // Split the 'current.variables.application' value
    var apps = current.variables.application.split(',');

    // Iterate through the 'apps' array and add to the query string
    for (i = 0; i < apps.length; i++) {
        subscription.condition += 'u_affected_ciLIKE' + apps[i] + '^OR';
    }
}

View solution in original post

13 REPLIES 13

YEs,

 

In here you are building the Encoded query. So either build the encoded query in a way that it adds multiple values separated by , in the below way

 

subscription.condition = '^u_affected_ciINa,b,c,d' ;

 

Instead of abcd provide multiple applications separated by ,

 

-Anurag

subscription.condition = '^u_affected_ciLIKE' + current.variables.application;

Do you know how I can get it to add all of the selected applications as or statements? The user can select multiple applications and all of those needs to be added to the condition builder as or statements 

Is 'current.variables.application' a reference variable or a list collector variable?  Is 'u_affected_ci' a reference field or a list field?

current.variables.application is a List Collector variable that references the CI table and and u_affected_ci is a list type field that references the CI table