Calling System Property in Business Rule

Raksha6
Kilo Contributor

Hello,

I'm working on a Business Rule that functions as expected, however I need to figure out a way to remove the hard-coded sysIDs from the script. I'm thinking that storing the values in a system property and calling it from the BR would be best practice, but not sure how to incorporate this logic into my code. Any guidance would be greatly appreciated!

Business Rule:

 
(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var control_owners = [];
    var unique_control_owners = [];
    var eventparm2 = "";
    var eventparm3 = "";
    var filter = "";
    //Check if user is Control Owner & Entity = IT Enterprise SW App or IT Telecom
    var gr = new GlideRecord('sn_compliance_control');
    gr.addEncodedQuery("state!=retired^key_control=true^profile=d41622692fbe81107fcc136a2799b6c1^ORprofile=9c1662692fbe81107fcc136a2799b61c^ownerLIKE" + current.sys_id);
    gr.query();
    while (gr.next()) {
        if (gr.u_admin_owner.toString().indexOf(",") > -1) {
            var temp = gr.u_admin_owner.toString().split(",");
            for (var i = 0; i < temp.length; i++) {
                control_owners.push(temp[i]);
            }
        } else {
            control_owners.push(gr.u_admin_owner.toString());
        }
    }
    unique_control_owners = new ArrayUtil().unique(control_owners);
    for (var j = 0; j < unique_control_owners.length; j++) {
        filter = "state!=retired^key_control=true^profile=d41622692fbe81107fcc136a2799b6c1^ORprofile=9c1662692fbe81107fcc136a2799b61c^ownerLIKE" + current.sys_id + "^u_admin_ownerLIKE" + unique_control_owners[j];
        eventparm2 = unique_control_owners[j] + "||" + filter;
        eventparm3 = filter + "||" + current.name.toString()+"||"+current.getTableName()+"||"+current.sys_id;
        gs.eventQueue("user.termination", current, unique_control_owners[j], eventparm2);
        gs.eventQueue("transfer.termination.records", current, unique_control_owners[j], eventparm3);
    }

    var executive_owners = [];
    var unique_executive_owners = [];
    //Check if user is Administrative Owner & Entity = IT Enterprise SW App or IT Telecom
    var gr2 = new GlideRecord('sn_compliance_control');
    gr2.addEncodedQuery("state!=retired^key_control=true^profile=d41622692fbe81107fcc136a2799b6c1^ORprofile=9c1662692fbe81107fcc136a2799b61c^u_admin_ownerLIKE" + current.sys_id);
    gr2.query();
    while (gr2.next()) {
        executive_owners.push(gr2.u_executive_owner.sys_id.toString());
    }
    unique_executive_owners = new ArrayUtil().unique(executive_owners);
    for (var k = 0; k < unique_executive_owners.length; k++) {
        filter = "state!=retired^key_control=true^profile=d41622692fbe81107fcc136a2799b6c1^ORprofile=9c1662692fbe81107fcc136a2799b61c^u_admin_ownerLIKE" + current.sys_id + "^u_executive_owner=" + unique_executive_owners[k];
        eventparm2 = unique_executive_owners[k] + "||" + filter;
        eventparm3 = filter + "||" + current.name.toString()+"||"+current.getTableName()+"||"+current.sys_id;
        gs.eventQueue("user.termination", current, unique_executive_owners[k], eventparm2);
        gs.eventQueue("transfer.termination.records", current, unique_executive_owners[k], eventparm3);
    }

    //Check if user is Executive Owner & Entity = IT Enterprise SW App or IT Telecom
    var gr3 = new GlideRecord('sn_compliance_control');
    gr3.addEncodedQuery("state!=retired^key_control=true^profile=d41622692fbe81107fcc136a2799b6c1^ORprofile=9c1662692fbe81107fcc136a2799b61c^u_executive_owner=" + current.sys_id);
    gr3.query();
    if (gr3.getRowCount() > 0) {
        filter = "state!=retired^key_control=true^profile=d41622692fbe81107fcc136a2799b6c1^ORprofile=9c1662692fbe81107fcc136a2799b61c^u_executive_owner=" + current.sys_id;
        eventparm2 = "Termination||" + filter + "||" + current.name.toString();
        eventparm3 = filter + "||" + current.name.toString()+"||"+current.getTableName()+"||"+current.sys_id;
        gs.eventQueue("executive.owner.termination", current, "TestEmailAddress@gmail.com", eventparm2);
        gs.eventQueue("transfer.terminaton.records", current, "TestEmailAddress@gmail.com", eventparm3);
    }

})(current, previous);​

 

1 ACCEPTED SOLUTION

Hi,

I'm unsure what you mean by "that didn't work", as what I provided does in fact work.

If you don't give us all the details, we can't really respond with a more precise answer for you.

With that said, if you have 10 sys_ids, you can store them in one property as JSON such as:

{"team_1":"sys_id_1","team_2":"sys_id_2"}

Then in your business rule script, you can use:

var obj = gs.getProperty('property_name');
obj = JSON.parse(obj);
gr.addEncodedQuery("state!=retired^key_control=true^profile=" + obj.team_1 +"^ORprofile=" + obj.team_2 + "^ownerLIKE" + current.sys_id);

Again, just examples, but you can take it from here.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

10 REPLIES 10

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi,

Value of system property can be retrieved using "gs.getProperty(<property name>)"

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi again,

Instead of putting sys_id's in system property, it may be better to dot-walk on field name and use the value instead of sys_id.

Unfortunately, I don't have "sn_compliance_control" in my instance but if profile has a name field, do something like below.

filter = "state!=retired^key_control=true^profile.name='profile1'^ORprofile.name='profile2'^ownerLIKE" + current.sys_id + "^u_admin_ownerLIKE" + unique_control_owners[j];

Allen Andreas
Administrator
Administrator

Hi,

If you're referring to your "addEncodedQuery" lines, then you can create a system property with a value that is that sys_id and then use something like this in your script:

gr.addEncodedQuery("state!=retired^key_control=true^profile=" + gs.getProperty('sys_id_1')+"^ORprofile=" + gs.getProperty('sys_id_2') + "^ownerLIKE" + current.sys_id);

The above is just an example of how to incorporate retrieving a system property into your existing code.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!