How to fetch the input value variable and set that value into variable of variable set

Sravan33
Tera Contributor

Query: How to fetch the input value of catalog item variable and set that value into  variable of variable set which are both placed in the same catalog item.

 

Consider 

1)"u_name" is catalog item variable (not part of that variable set)

   u_name = Servicenow

2)"u_id"   is catalog item variable (not part of that variable set)

    u_id  =7766889

3) u_details = 

now value of  u_name and u_id should be display in variable of variableset i.e u_details 

Note- u_details is part of variable set which is in same catalog item

 

 FINAL OUT PUT=u_details = Servicenow_7766889

 

Thanks in advance 

 

 

4 REPLIES 4

Iraj Shaikh
Mega Sage

Hi,

 

You need to create two onChange catalog client scripts as shown below:

1. Set u_details - on change of u_name:

IrajShaikh_0-1701938749936.png

 

 

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

    // Fetch the values of u_name and u_id
    var u_name = g_form.getValue('u_name');
    var u_id = g_form.getValue('u_id');

    // Concatenate u_name and u_id and set the value of u_details
    var u_details_value = u_name + '_' + u_id;
    g_form.setValue('u_details', u_details_value);
}

 

 



2. Set u_details - on change of u_id

IrajShaikh_1-1701938828836.png

 

 

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

    // Fetch the values of u_name and u_id
    var u_name = g_form.getValue('u_name');
    var u_id = g_form.getValue('u_id');

    // Concatenate u_name and u_id and set the value of u_details
    var u_details_value = u_name + '_' + u_id;
    g_form.setValue('u_details', u_details_value);
}

 

 


Please mark it helpful, if I answered your question.

Sravan33
Tera Contributor

Hi @Iraj Shaikh 

 Thanks for your response.

the script which you provided work perfectly only for variables.

But,

Here u_name and u_id both are variables, u_details is part of variable set variable. now the requirement is the input of two variables should be display in variable set variable i.e u_details.

the script which you provided work for variables    

Hi @Sravan33 


The catalog client scripts above contains u_details variable and it is part of a variable set. 

It works. I have tested in my PDI.

IrajShaikh_0-1701940591692.png

 

IrajShaikh_1-1701940817868.png

 

Please mark it helpful, if I answered your question.

Shamma Negi
Kilo Sage
Kilo Sage

Hi,

 

Please use the below script:

 

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

// Fetch the values of u_name and u_id
var u_name = g_form.getValue('u_name');
var u_id = g_form.getValue('u_id');

// Concatenate u_name and u_id and set the value of u_details
var u_details_value = u_name + '_' + u_id;
g_form.setValue('<variable set internal name>.u_details', u_details_value);
}

Regards,Shamma Negi