Error: Cannot read property "variables" from undefined,Detail: Cannot read property "variables" from undefined

Tomi Corigliano
Kilo Sage

Hi,

I'm trying to update the variable 'request reason' of a requested item which has been created through service portal:

find_real_file.png

In the flow designer I created an action with the following inputs:

find_real_file.png

I added a script step with the following script:

find_real_file.png

When I run the following test:

find_real_file.png

I get the following error message:

find_real_file.png

Thanks in advanced for your assistance

 

4 REPLIES 4

Vamsi Sreenivas
Giga Guru

Hi, the error suggests that there is no record key in inputs. Go through below link which might help you:

https://community.servicenow.com/community?id=community_question&sys_id=f8c0e5601b66a41038739979b04b...

 

Regards,

Vamsi S

Also check the record you choose to test RITM0010029 has variables in it as your first screenshot shows RITM0010032 which has variables.

Sam Scott1
Tera Expert

After hours of searching for a solution to a similar problem, I found this page in the documentation about the script step of Action Designer. Hidden half-way down the page is the following line.

The Script step always converts data stored in the inputs and outputs global objects into strings.

 
So actions can have objects as inputs, but the script step flattens them before bringing them into the script. This means that before you can call record.variables, you need to convert record from a string into a GlideRecord. For anyone reading this in the future, this can be done by adding the following lines before calling record.variables.

var record = new GlideRecord('sc_req_item'); //consider passing this as an input instead of hard coding
record.get(inputs.record); //inputs.record is now a sys_id. We are converting it to a request record.
record.variables[inputs.variable] = inputs.value;

 

If working with JSON objects, like I was, call JSON.parse(input.record) to rebuild as an object.

What  if we are trying to set a flow variable 

latroyamitchell_0-1716338555345.png

latroyamitchell_2-1716338603377.png