Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Does anyone know how to access the order guide variables from the order guide script field?

johnnysharp
Tera Contributor

I would like to be able to access an order guide variable to use for a loop in the order guide script field. Does anyone know of a way to access the order guide variables within the order guide script field?

I have tried:

current.vars.<variable_name>

current.variables.<variable_name>

current.variable_pool.<variable_name>

guide.vars.<variable_name>

guide.variables.<variable_name>

guide.variable_pool.<variable_name>

13 REPLIES 13

Allen Andreas
Tera Patron

Please see my article regarding this topic, located here: https://community.servicenow.com/community?id=community_article&sys_id=61ccb3d9dbd0d110b5d6e6be13961...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Daniel Rubin
Tera Contributor

 

you can't access variables from an order guide, an order guide is intended to drive you to the proper catalog item, page 1 of the order guide is not intended to gather meaningful data, and if it is, you can use "cascading variables" to pass it to the catalog item on page 2, or you can use "item variable assignments" from the Rule Base record itself for the individual catalog item you want to pass it to. You need the information to move to the catalog item on page 2, as that is what gets submitted, the Order Guide is just a re-direct to help the customer navigate to the proper catalog item based on their needs. 

Abhishek Pal
Giga Guru

Hi @johnnysharp ,

You cannot reliably access Order Guide variables in the Order Guide Script field using:

current.variables.variable_name
guide.variables.variable_name

The Order Guide Script is server-side, and the documented guide object is intended primarily for adding/removing catalog items.

If you are using the native catalog UI, this pattern may work:

var value = g_request.getParameter('IO:<variable_sys_id>');

guide.add(value);

However, g_request is not available when the Order Guide is executed through Service Portal/Employee Center, so I would not use this if the guide must work across experiences.

Recommended approach:

If the variable is only being used to decide which items should be included, use an Order Guide Rule Base. This is the OOB and upgrade-safe approach because Rule Base conditions can evaluate the Order Guide variables directly.

If you genuinely require a dynamic loop that cannot be handled through Rule Base, pass the required variable values from a Catalog Client Script to the server and store/read them from the user's cart.

A commonly used approach is:

1. Capture the Order Guide variable from an onChange Catalog Client Script.
2. Send it server-side using GlideAjax.
3. Store the required values with the current catalog cart.
4. Read those values in the Order Guide Script.
5. Use guide.add() for the dynamically determined catalog items.

For example, once the value has been stored in the cart:

var cart = new sn_sc.CartJS();
var data = JSON.parse(cart.getSpecialInstructions() || '{}');

var selectedItems = data.selected_items || '';

if (selectedItems) {
var items = selectedItems.split(',');

for (var i = 0; i < items.length; i++) {
if (items[i])
guide.add(items[i]);
}
}

So the recommended order is:

Order Guide Rule Base
-> Use this whenever the requirement can be expressed through variable conditions.

Order Guide Script + guide.add()
-> Use only when genuinely dynamic server-side item selection is required.

I would not build the solution around current.variables or guide.variables because those objects do not expose the Order Guide variables in the Script field the way a Record Producer exposes producer variables.

Hope this helps!

If this response helped, please mark it as Helpful.
If it resolves your issue, please Accept it as Solution.

Kind Regards,
Abhishek Pal