Reference qualifier is not working properly

Brijmohan
Tera Contributor

Hi All, I am working on record producer where I have 3 variables L1 category, L2 category and L3 category. I need to set these variables values depended on each other. I am able to get the values based on filter applied in script include but it is working only first time. Is there anything that I am missing in my script or any way to achieve this requirement and should give filtered record on every selection not only first time.

 

Scenario 1: If user select L1 category then only child categories should show in L2 category variable.

Result : It is showing only child categories like we have a, b and c three child categories and I selected a but when I want to change other category in L2 variable it is showing no record found.

 

Scenario 1: If L1 and L3 is empty then only those categories should show whose have child and parent category.

Result : It is showing categories as per filter but when I want to change other category in L2 variable it is showing no record found.

 

PFB script include that I am using in reference qualifier.

 

 

getLevel2Category: function(L3Category, L1Category) {
        var returnIds = [];
        var grModelCategory = new GlideRecord("cmdb_model_category");
        if (!L1Category) {
            if (!L3Category) {
                // check if parent category is not empty
                grModelCategory.addEncodedQuery("parent_cateogryISNOTEMPTY");
                grModelCategory.query();
                while (grModelCategory.next()) {
                    // Ensure the current category should have any child categories
                    var childCategoryCheck = new GlideRecord("cmdb_model_category");
                    childCategoryCheck.addQuery("parent_cateogry", grModelCategory.sys_id);
                    childCategoryCheck.query();
                    if (childCategoryCheck.hasNext()) {
                        var tempId = grModelCategory.getUniqueValue();
                        returnIds.push(tempId);
                    }
                }
            }
        } else {
            // Query for child categories with the specified parent category
            var encQuery = "parent_cateogry.sys_id=" + L1Category;
            grModelCategory.addEncodedQuery(encQuery);
            grModelCategory.query();
            while (grModelCategory.next()) {
                tempId = grModelCategory.getUniqueValue();
                returnIds.push(tempId);
            }
        }
             return "sys_idIN" + returnIds.toString();   
    },

 

 

 

Variable configuration

Brijmohan_0-1718713493201.png

 

Brijmohan_1-1718713544697.png

 

Thanks and regards,

Brijmohan

 

 

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Brijmohan 

no where in your script include function query you are using the value of the previous variable which should be used to filter

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi @Ankur Bawiskar Thanks for you response but I didn't get you. If you are talking about query, I am using below condition if we have any value in L1 category in else condition

 

var encQuery = "parent_cateogry.sys_id=" + L1Category;
grModelCategory.addEncodedQuery(encQuery);

 

where L1Category contain value of L1 variable.

@Brijmohan 

what about L3Category variable? you are not using it anywhere

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

L3Category variable I am using in if condition for checking L3 category is empty or not like below

if (!L1Category) {
if (!L3Category) {

 

Code is working fine but the only issue is it is working only first time. Suppose I select category in L1 category field then L2 will show all child category. I select one category in L2 category field but when i go to choose other option it is giving no matches found. PFB snap.

First time selection

Brijmohan_0-1718769924909.png

 

Second time selection

Brijmohan_1-1718769967424.png