Script Cannot retrieve requested item variable

johnfeist
Mega Sage
Mega Sage

I know that this makes no sense, but it's happening.

 

I have a catalog item with a handful of variables plus a few variable sets.  In the workflow scripting I have a few lines that look like this:

 

var theBusiness = current.variables.what_business;
workflow.info("theBusiness " + theBusiness);
 
When that executes, theBusiness displays as undefined. That happens when I try to get the
value for any of the variables defined on this item. However if I execute the same for a
variable from a variable set, I get the correct value.
 
I have code like the above that runs correctly in any number of scripts, workflows, etc.
 
It doesn't matter if I try to retrieve the value in the workflow or just in a little test
script. If I go the route of querying sc_item_optiom_mtom and then go into the values in
sc_item_option I get what I need.
 
Do you have any idea why I'm only seeing this behavior for one item?
 
TIA for any insights you can provide,
 
:{)

 

 

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster
6 REPLIES 6

Hello @johnfeist 

 

Try with below 👇 

 

var ritm = new GlideRecord('sc_req_item');

if (ritm.get('<sys_id_of_ritm>')) {

    var selectedValue = ritm.variables.priority;

    gs.log("Fetched Select Box Value: " + selectedValue)

;

}

Workflows usually run as the 'system' user.  When a user interacts with the RITM via an approval or update and there is a Run Script activity immediately following in the workflow, then the Run Script will likely run as that user, which doesn't sound like it should matter in this case but has caused lots of hair pulling when something works in some test cases but not others.  Since you can see the variables and values on the RITM record, what happens when you try similar code in a display Business Rule? I don't think this would matter, but is there any difference on the Availability tab of these variables compared to those in other Catalog Items?  Do these variables have the Global box checked or unchecked compared to others? Is this Catalog Item in a Catalog or Category that's different than all others?