How to set the value of a variable in a variable set for different Catalog Items

ID NOBLE
Tera Expert

Hello,

 

I have a requirement to set the value of a variable created in a variable set. For instance, we have a Variable Set named "Regional Accounts" variable set. And in the variable set, we have a Variable named "Location". So, I was asked to set the value of that variable "LOCATION" for a particular Catalog Item because the value of "LOCATION" variable differs by the different Catalog Items we have.

 

How can I achieve this please?

 

Thanks in advance.

3 REPLIES 3

SAI VENKATESH
Tera Sage
Tera Sage

Hi @ID NOBLE 

 

can You provide some more information ?

 

Thanks and regards

Sai Venkatesh

Hi @SAI VENKATESH,

I have a requirement to set the value of a variable created in a variable set. For instance, we have a Variable Set named "Regional Accounts" variable set. And in the variable set, we have a Variable named "Location". So, I was asked to set the value of that variable "LOCATION" for a particular Catalog Item because the value of "LOCATION" variable differs by the different Catalog Items we have.

Hi @ID NOBLE 

You can write a onLoad client script within the variable set and read the current catalog name and set the location column value.

 

function onLoad(control, isLoad, isTemplate) {
    // Get the current catalog item
    var catalogItem = g_form.getParameter('sysparm_catalog_view');

    // Check if the catalog item name matches a specific value
   // replace the catalog item sys_id 
    if (catalogItem === 'sys_id of catalog1') {
        // Catalog item name matches, perform desired actions
        // For example, you can display a message or set a field value
        g_form.setValue("location", '<LocationValue1>'); // update the corrent variable name for location field
    } else if (catalogItem === 'sys_id of catalog2') {
       g_form.setValue("location", '<LocationValue2>'); // update the corrent variable name for location field
    }
}

 

-Thanks,
AshishKM


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