Show Help Text in a Catalog Item only when Sub-Category choice Value is 'User Access'

Bijay Kumar Sha
Giga Guru

I've one catalog Item where there are 2 Drop Down Choice fields called as 'Category' and Sub Category'. All the choice fields in Sub Category are depended upon Category Choice List values.

However, there is one Choice list value in Sub Category exist with name as 'User Access'.

My requirement is that, when requester selects the value 'User Access' in Sub Category', then automatically, one Help text should get appear under Sub Category Variable with some information let's say "abcd". For other choice list values, it should be hidden.

How I can achieve this?

Please see the OnChange Client Script that I'm using as below, but it's not working for me. 

BijayKumarSha_0-1712745681582.png

 

Please let me know if I'm doing any mistake over here

3 REPLIES 3

Deepak Shaerma
Kilo Sage

Hi @Bijay Kumar Sha 

Step 1: Create An Information Variable
1. Go to your Catalog Item.
2. Add a new variable:
Type: Information (or HTML, depending on how you want to display the text).
Name: Provide a name (e.g., “User Access Help”).
Question: Enter the help text you want to show when ‘User Access’ is selected in ‘Sub Category’ (e.g., “abcd”).
3. Save the variable. Note that by default, this variable will be visible.

Step 2: Create a Client Script
1. In the Catalog Item form, navigate to the “Client Scripts” related list and click on “New” to create a new client script.
2. Configure your Client Script as follows:
Name: Give it a meaningful name (e.g., “Show Help Text on Sub Category Selection”).
Type: OnLoad (You might consider onChange subcategory if you want the script to work when the value changes).
UI Type: Desktop or Both, depending on where you need it to run.
Variable set: Leave blank if the script is directly associated with the item and not a variable set.
Script: Enter the script provided below.
3. Save the Client Script.

 

function onLoad() {
    // Replace ‘subcategory’ with the actual variable name of your Sub Category choice field
    var subCategoryField = g_form.getControl('subcategory');
    // Replace ‘user_access_help’ with the variable name of your Information variable
    var helpTextVariableName = 'user_access_help';
    
    // Hide the help text variable by default
    g_form.hideFieldMsg(helpTextVariableName, true);
    
    // Add an event listener to the Sub Category field
    if (subCategoryField) {
        subCategoryField.onchange = function() {
            updateHelpTextVisibility();
        };
    }
    
    // Ensure the correct visibility when the form loads
    updateHelpTextVisibility();

    function updateHelpTextVisibility() {
        // Get the current value of the Sub Category field
        var subCategoryValue = g_form.getValue('subcategory');
        
        // Show the help text only if ‘User Access’ is selected, hide otherwise
        // Replace ‘user_access’ with the actual value that represents ‘User Access’ in your choice list
        if (subCategoryValue === 'user_access') {
            g_form.hideFieldMsg(helpTextVariableName, false); // Show the help text
            g_form.showFieldMsg(helpTextVariableName, "abcd", 'info', false); // Replace “abcd” with your actual help text or conditionally set this
        } else {
            g_form.hideFieldMsg(helpTextVariableName, true); // Hide the help text
        }
    }
}

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma



Harish13696
Tera Contributor

Hi @Bijay Kumar Sha 

Try this Onchange script
var subCategoryValue = g_form.getValue('subcategory'); // Replace 'subcategory' with the actual field name of Sub Category

if (subCategoryValue === 'User Access') {
g_form.setDisplay('help_text_field', true); // Replace 'help_text_field' with the actual field name of the help text
g_form.setLabelOf('help_text_field', 'User Access Help'); // Replace 'help_text_field' with the actual field name of the help text
} else {
g_form.setDisplay('help_text_field', false); // Replace 'help_text_field' with the actual field name of the help text
}

}


var subCategoryValue = g_form.getValue('subcategory'); // Replace 'subcategory' with the actual field name of Sub Category

if (subCategoryValue === 'User Access') {
g_form.clearMessages(); // Clear any existing messages
g_form.addInfoMessage('This is the help text for User Access.'); // Display an information message
} else {
g_form.clearMessages(); // Clear any existing messages
}
}