Order Guide - Set Values Via Script

DylanBlumenberg
Tera Contributor

Hi all, 

 

We have an order guide with checkbox fields for Visio, Project, and Power BI. If any of those are checked, it will select a catalog item called Microsoft Applications. This catalog item uses a list collector to allow users to select one or multiple of these applications. When the checkbox fields are checked, I want to auto-populate the catalog item list collector with the options chosen. 

 

I started with a rule base for each option, and they replace, not add the option to the list collector field. Additionally, creating 9 rule bases for every combo is not a good idea. 

 

Next I tried an onLoad catalog client script to check if a checkbox is checked, then combine all sys_ids for the list collector options and add to the field but this didn't work either. This script is below.

I tried having it run on the catalog item and the order guide, onChange and onLoad, but nothing worked.  

 

(Full disclosure, I am not a developer, so the script was generated with the help of AI)

function onLoad() {

    // Create an array to hold the sys_ids of the applications to add.
    var applicationsToAdd = [];

	//Set variables for Microsoft Office Application choices
    var visioSysId = 'e81e79e33b7aa210e7aa2f2eb3e45a99';
    var projectSysId = '1a1eb5273b7aa210e7aa2f2eb3e45ae9';
    var powerBiSysId = 'f82ebde33b7aa210e7aa2f2eb3e45aed';

    // Check each cascaded checkbox variable from the Order Guide.
    if (g_form.getValue('microsoft_visio') == 'true') {
        applicationsToAdd.push(visioSysId);
    }
    if (g_form.getValue('microsoft_project') == 'true') {
        applicationsToAdd.push(projectSysId);
    }
    if (g_form.getValue('microsoft_power_bi') == 'true') {
        applicationsToAdd.push(powerBiSysId);
    }

    // Set the value of the list collector.
    g_form.setValue('applications', applicationsToAdd.join(','));
}

 

Does anyone know how I can accomplish my goal?

3 REPLIES 3

Swapna Abburi
Mega Sage
Mega Sage

Hi @DylanBlumenberg 

Did you create those 3 checkbox variables in "Microsoft Applications" catalog item as well? If not, create those 3 checkboxes with same variable name as in order guide and select cascade variables option on the order guide.

 

After this step, the on-load client script you have written should work. 

Hi Swapna, the checkbox variables do not exist on the "Microsoft Applications" catalog item. I was attempting to "translate" the checkboxes on the order guide to values on the list collector.

Hi @DylanBlumenberg

Its a best practice to create variables on indivudal catalog item using cascade option if the responses on order guide needs to be used in the catalog item.

 

Otherwise you need to store variables on order guide as session variables. May be not a good practice.