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

Anurag Tripathi
Mega Patron
Mega Patron

replace 

subscription.condition = '^u_affected_ci = current.variables.application';

with

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

-Anurag

Edwin Fuller
Tera Guru

This gets me closer since it's setting the sys_id of the selected application. Is there a way to set the operator to 'contains' and get the display value instead of the sys_id?

 

find_real_file.png

Use the below

 

subscription.condition = '^u_affected_ci ='+current.variables.application.getDisplayValue();

-Anurag

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