Using variable conditions builder

bhupindersinghr
Kilo Contributor

I was wondering if there could be a way to mimic the condition builder which is on Catalog UI Policy where selecting a catalog item gives an option to select a variable from the "catalog conditions" field. 

I have created a form with Catalog item and Condition field (dependent on catalog item). And the requirement is to show the variables in the filter option-

find_real_file.png  

13 REPLIES 13

You probably don't have this requirement anymore, but I just wanted to chime in with a solution I just got working. 

Setting up your field just like you did, if you just add an onLoad Client Script that calls the GlideFilter constructor like this, it will make your Catalog Conditions field work.

function onLoad() {
    new GlideFilter("sn_hr_sp_dropzone_config.u_conditions", g_form.getValue("u_conditions"), null, false, false, function(filter) {
        filter.tableOptions = {
            onBeforeReadColumns: function(ajax) {
                ajax.addParam("sysparm_condition_builder", "true");
                ajax.addParam("get_catalog_variables", "true");
                ajax.addParam("sysparm_sys_id", g_form.getValue("u_record_producer"));
                ajax.addParam("sysparm_record_scope", "global");
                ajax.addParam("sysparm_value", "catalog_ui_policy");
            }
        };
    });
}

The first argument is <table_name>.<field_name>

The second is the query to add (will most likely just be the same field as your Catalog Conditions field)

Third, fourth and fifth I'm not entirely sure what are used for, but I just left them off.

The final argument is a callback function, and you'll need to set the filter's tableOptions property to an object with the onBeforeReadColumns function as specified. 

 

Whenever a GlideFilter is used on a non-Catalog UI Policy table, it seems to always grab the variables that are on the actual table the Catalog Conditions variable is defined on. In my case, that would be sn_hr_sp_dropzone_config. If you instead just set sysparm_value=catalog_ui_policy, event though the table isn't Catalog UI Policy, it grabs the variables from the Record Producer specified in sysparm_sys_id.

 

Here's my Catalog Conditions field (Conditions) on my custom table Dropzone Config. There's a Record Producer in a reference field called u_record_producer, that it's currently pulling the variable test_string from.

MathiasJepsen_2-1742414160939.png

 

Saving the record after setting some conditions will correctly save it in the database, and the onLoad Client Script will load it in the Conditions field on the form, just like in a regular Catalog Conditions field.

 

I hope this helps you.

 I have to say that you saved my life, thank you!!!!

This is amazing!! Thank you so much. I'm working on delivering an app for standardising Flows, and this was the missing link I needed to tie it all together and make it super user friendly.I'm curious to know how you discovered this.

 

Just a note to anyone else working on a similar requirement - this does also work in scoped applications. The sysparm_record_scope should be left as "global" assuming your catalog variable records are still in the global scope.

Hey Chris,

 

I can't remember exactly how I figured it out, but usually the process I go through when I run into a problem like the above is to head to the Sources tab in the browser console, and just spend a while looking around 😄

 

Even just doing a console.log() of certain OOB things (such as g_form) in a Client Script can help out a lot, because you're then able to see all the functions available, and can click a link in the property called "FunctionLocation" on any of the functions, which will take you straight to the actual file in the Sources tab, and from there you can go deeper down the rabbit hole, haha