catalog item form design

Murali Reddy
Tera Contributor

I am working on Catalog item form designing part of that Role type and Role name two variables are created. in Role type variables are having jar1, jar2 options are having , in Role Name variable having the options Mug1,mug2,mug3,mug4,mug5,mug6.

suppose if select the jar1 option in Role type filed then Role Name variable will shown mug1,mug2,mug3

suppose if i select the jar2 option in role type field then role name field will shown mug4,mug5,mug6

suppose if i select the jar1,jar2, at the same time in Role Type field then Role Name field will shown mug1,mug2,mug3,mug4,mug5,mug6

how to achieve this one?

2 ACCEPTED SOLUTIONS

Hello @Murali Reddy 

I have the solution to your question. Please follow the following process.

1. Role Type: List Collector

  •  Create two choices in Question Choice table
    • Jar1 and Jar2
  • Set the reference qualifier to the variable like below
    • question=3b050ddb83d8a21038cfc7e0deaad309 //sys_id of your role type variable

2. Role Name: List Collector

  • Create 6 choices in Question Choice table
    • Mug1,mug2,mug3,mug4,mug5,mug6
  • Set the reference qualifier to the variable like below
    • question=cf95011f83d8a21038cfc7e0deaad3bc   //sys_id of your role name variable

3. Create a custom field in Question Choice

  • Type: Reference
  • Reference Table: Question Choice
  • Label: Dependant Value

4. Set the dependent value in the question choice table like below

RushiSavarkar_3-1742553482858.png

 

5. Create a client callable script include

var ADAPICall = Class.create();
ADAPICall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getRoles: function() {
		var rolenames = [];
        var roleType = this.getParameter('sysparm_type');
        var gr = new GlideRecord('question_choice');
		gr.addQuery("question", "place_your_question_sys_id"); // Role Name question sys_id
		gr.addEncodedQuery("u_dependant_value.sys_idIN" + roleType);
        gr.query();
        while (gr.next()) {
           rolenames.push(gr.sys_id.toString());
        }
        return rolenames.join(',');
    },

    type: 'ADAPICall'
});

6. Create OnChange Catalog Client script on Role Type variable

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
		g_form.clearValue("role_name");
        return;
    }
    var roleType = g_form.getValue('role_type');
    var getRoleNames = new GlideAjax('ADAPICall');
    getRoleNames.addParam('sysparm_name', 'getRoles');
    getRoleNames.addParam('sysparm_type', roleType);
    getRoleNames.getXML(callBack);

    function callBack(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        alert(answer);
            g_form.setValue('role_name', answer);
    }

 Output: 

1. 

RushiSavarkar_0-1742553287174.png

2. 

RushiSavarkar_1-1742553324653.png

3. 

RushiSavarkar_2-1742553350777.png

 

If my response helped you, please accept the solution and mark it as helpful.
Thank You!

View solution in original post

Hello @Murali Reddy 

Have you tried the solution mentioned above?

If my response helped you, please accept the solution and mark it as helpful.
Thank You!

View solution in original post

9 REPLIES 9

Hi Rushi,

 

    Thanks for teh your reply and your anse perfect to me and i have one more requirement like this 

     Role Type having two option , now this variable type is Select box type and Role name variable also Select box type

Role Type -Jug1,

                 -Jug2

Role Name -Mug1,mug2,mug3,mug4

If i select Role Type -Jug1 --------Role Name -Mug1 or mug2 (Only one option able to select)

like is i select Role Type -Jug2   ----Role Name -Mug3 or mug4 (only one option able to select)

for this can you please provide me the client script

 

I have the solution ready for the first requirement

Role Type and Role Name will be select box type variable

Role Name variable will have 4 choices

The syntax of addOption and removeOption method is:

g_form.addOption("variable_name","choice_value","choice_label");

g_form.removeOption("variable_name","choice_value","choice_label");

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
		g_form.removeOption('role_name1', 'NGK_RJ', 'NGK_RJ');
        g_form.removeOption('role_name1', 'RGK_LK', 'RGK_LK');
		g_form.removeOption('role_name1', 'consumer_reporting', 'consumer_reporting');
        g_form.removeOption('role_name1', 'customer_reporting', 'customer_reporting');
        return;
    }
	alert(newValue);
    if (newValue == 'NAWM') {

        g_form.addOption('role_name1', 'NGK_RJ', 'NGK_RJ');
        g_form.addOption('role_name1', 'RGK_LK', 'RGK_LK');

        g_form.removeOption('role_name1', 'consumer_reporting', 'consumer_reporting');
        g_form.removeOption('role_name1', 'customer_reporting', 'customer_reporting');

    } else if (newValue == 'SCReport') {
        g_form.addOption('role_name1', 'consumer_reporting', 'consumer_reporting');
        g_form.addOption('role_name1', 'customer_reporting', 'customer_reporting');

        g_form.removeOption('role_name1', 'NGK_RJ', 'NGK_RJ');
        g_form.removeOption('role_name1', 'RGK_LK', 'RGK_LK');

    }

}

 

If my response helped you, please accept the solution and mark it as helpful.
Thank You!

Ankur Bawiskar
Tera Patron
Tera Patron

@Murali Reddy 

assuming both the variables are of type drop down, use this script and enhance based on your variable name and choice label and choice values

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    // Define the options for each Role Type
    var roleNameOptions = {
        jar1: ['mug1', 'mug2', 'mug3'],
        jar2: ['mug4', 'mug5', 'mug6']
    };

    // Get the selected Role Type values
    var selectedRoleTypes = g_form.getValue('role_type').split(',');

    // Determine the options to display in the Role Name variable
    var optionsToShow = [];
    selectedRoleTypes.forEach(function(roleType) {
        if (roleNameOptions[roleType]) {
            optionsToShow = optionsToShow.concat(roleNameOptions[roleType]);
        }
    });

    // Remove duplicates and sort the options
    optionsToShow = Array.from(new Set(optionsToShow)).sort();

    // Clear the Role Name variable options
    g_form.clearOptions('role_name');

    // Add the new options to the Role Name variable
    optionsToShow.forEach(function(option) {
        g_form.addOption('role_name', option, option);
    });
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi Ankur,

      Thanks for the solution but here the requirement is i want  to select the one or two option at a time in Role type field at the same time i want select the options(filed) related to select t Role Name field also. That's why i choose Role type field is List collector.

 

ex: if i select role type is: jar1 then Role name field able to select :mug1,mug2,mug3

    if i select role type is :jar2 then Role name field able to select :mug4,mug5,mug6

suppose if select jar1,jar2 at time in role type then also i am able to select Role Name field : mug1,mug2,mug3,mug4,mug5,mug6

@Murali Reddy 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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