How to populate a variable on the cart with a select box

Joshua Comeau
Kilo Sage

EX:

var category = gs.info(current.u_category);
cart.setVariable(item, 'category', current.u_category);
 
but not working as it is creating a new selection on the variable not using the existing choices?
4 REPLIES 4

The Matrix
Tera Contributor

Hi @Joshua Comeau Try below code 

var categoryValue = current.u_category; 
gs.info('Category Value: ' + categoryValue);
cart.setVariable(item, 'category', categoryValue);

Use gs.info() or gs.log() to debug the values and ensure that categortyValue is being set correctly and matches a choice. 

Did not work so I am using a scheduled job script to run to create and populate the cart.

JoshuaComeau_0-1720452329999.png

that code did not even populate any or add a choice any idea?

Strings and reference fields work fine

but select boxes do not 

Did this:

JoshuaComeau_0-1720452763679.png

 

SN_Learn
Kilo Patron
Kilo Patron

Hi @Joshua Comeau ,

 

Try the below:

var category = gs.info(current.u_category);
var getCategory = current.u_category.getDisplayValue();
cart.setVariable(item, 'category', getCategory);

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.