Change Variable Question based on Condition in Catalog Item

Snow_Hustler42
Tera Contributor

Is it possible to change the question value based on condition?

 

For example, we've a catalog item wherein multiple variables available like:

-service provider(multiple choice[a,b,c,d]).

-request type(multiple choice--[x,y]).

-account number(single line text)

 

when service provider is 'b' and request type is 'y', then the variable 'account number' should be changed to 'account ID'(only the question should change).

#itsm #catalog item

 

There is an option to create 2 variables each for account number and account ID, then use Catalog UI policy based on condition; however, is there any other way to do it without creating multiple variables.  I've tried onchange CS with g_form.setLabelof() but isn't helping.

 

Gurus, please help me with the Catalog CS code..

 

Thanks in Advance

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hello @Snow_Hustler42 ,

Hope you are well!

In the catalog item, when 'Service Provider' is 'b' and 'Request Type' is 'y', dynamically change the label of the 'Account Number' variable to 'Account ID'.

Solution:

1. We have to configure 2 onChange client scripts for the variables 'Service Provider' and 'Request Type' like below. 
#onChange Client Script for Service Provider:

PrasadS_0-1690386203356.png

 

Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //g_form.addInfoMessage(newValue + "\n" + g_form.getValue('request_type'));
    //Type appropriate comment here, and begin script below
    if (newValue == 'b' && g_form.getValue('request_type') == 'y') {
        g_form.setLabelOf('account_number', 'account ID');
    } else {
        g_form.setLabelOf('account_number', 'account number');
    }
}

 

# 2 onChange Client Script for 'Request Type':

PrasadS_1-1690386298576.png

Script:

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

    //Type appropriate comment here, and begin script below
    //g_form.addInfoMessage(newValue + "\n" + g_form.getValue('service_provider'));
    //Type appropriate comment here, and begin script below
    if (newValue == 'y' && g_form.getValue('service_provider') == 'b') {
        g_form.setLabelOf('account_number', 'account ID');
    } else {
        g_form.setLabelOf('account_number', 'account number');
    }
}

 

If this helped you in any way, please hit the like button/mark it helpful. Also, don't forget to accept it as a solution. So it will help others to get the correct solution.

 

thanks,

Prasad

View solution in original post

7 REPLIES 7

Tried and isn't working

Sai Pusala
Tera Contributor

Hi @Snow_Hustler42 

you got any solution regrding this requirement. I am also having the same requirement like mentioned above.

Snow_Hustler42
Tera Contributor

Nope, I've confirmed the client that it's not a feasible option. Instead, I created 2 variables and hidden one of them using UI policy based on requirement. Having 2 questions for 1 variable will conflict in server side. Hence, it's not feasible