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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 07:02 AM
Hi,
I'm trying to update the variable 'request reason' of a requested item which has been created through service portal:
In the flow designer I created an action with the following inputs:
I added a script step with the following script:
When I run the following test:
I get the following error message:
Thanks in advanced for your assistance
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 07:19 AM
Hi, the error suggests that there is no record key in inputs. Go through below link which might help you:
Regards,
Vamsi S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 07:37 AM
Also check the record you choose to test RITM0010029 has variables in it as your first screenshot shows RITM0010032 which has variables.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2022 10:07 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-21-2024 05:43 PM
What if we are trying to set a flow variable