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

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';
    }
}

Doesn't populate at all now, let me try tweaking the code a little

 

find_real_file.png

I got it working by adding a line as you see below, thank you for the help, direction, and your time / patience. I am very thankful

 

var commaDelimetedapps = current.variables.application.toString();
var apps = commaDelimetedapps.split(',');

Edwin Fuller
Tera Guru

Thank you