Hide false checkboxes from RITM and Task

xhensilahad
Tera Expert

This is a requirement for my Catalog items in general.

If a checkbox variable type is not checked, it should be hidden in the RITM and Task.

 

I have created a Script Include to retrieve the RITM variable names and types. If type is 'checkbox' and value is 'false', the variable should be hidden.

 

I would appreciate some feedback as the scripts are not working as expected at the moment:

 

 

onLoad Catalog Client script

 

function onLoad() {
   
        var ga = new GlideAjax('VariableTypeChecker'); // Call the Script Include
        ga.addParam('sysparm_name', 'getVariableTypes'); // Specify the method to call
        ga.addParam('sys_id', ritmSysId);               // Pass the RITM sys_id
alert(test);
        ga.getXMLAnswer(function(response) {
            var variableTypes = JSON.parse(response); // Parse the JSON response
            alert(variableName, variableTypes)

            // Iterate through variables
            for (var variableName in variableTypes) {
                if (variableTypes[variableName] === 'checkbox') { // Check if it's a checkbox
                    var value = g_form.getValue(variableName);    // Get its value
                    if (value === 'false') {                      // If false, hide it
                        g_form.setVisible(variableName, false);
                    }
                }
            }
        });
    }


 
Script Include:
 
var VariableTypeChecker = Class.create();
VariableTypeChecker.prototype = {
    initialize: function() {},
    getVariableTypes: function(ritmSysId) {
        var variableTypes = {};
        // Query the requested item (RITM) record
        var ritm = new GlideRecord('sc_req_item'); // Table for requested items
        if (ritm.get(ritmSysId)) {
            // Get all variables for the RITM
            var variables = ritm.variables.getElements();
            // Iterate through the variables and get their types
            for (var i = 0; i < variables.length; i++) {
                var question = variables[i].getQuestion(); // Access variable metadata
                if (question) {
                    var name = question.getName();         // Variable technical name
                    var type = question.getType();         // Variable type (e.g., 'checkbox', 'string', etc.)
                    variableTypes[name] = type;            // Store in the result object
                }
            }
        }
        return variableTypes; // Return an object containing variable names and their types
    },
    type: 'VariableTypeChecker' // Script Include name
};

 

 

Thank you

4 REPLIES 4

AshishKM
Kilo Patron
Kilo Patron

Hi @xhensilahad ,

Did you try to Catalog UI Policy and Action, you can check  that "if a checkbox is checked or not".

What is need of GlideAjax here.

 

-Thanks,

AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Hi Ashish,

I need to dynamically hide all the checkboxes that were not selected,

Community Alums
Not applicable

You can do the same using the catalog UI Policy, configuring the UI policy to apply the changes to catalog tasks and requested items.

You can check the fields below in the catalog UI policy. 

SheezanAhmK_0-1733826506261.png

 

Regards,

Sheezan.

PrashantLearnIT
Giga Sage

Hi @xhensilahad 

 

For the best solution try to use the Catalog UI Policy to work this requirement in RITM and CTasks.

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************