Hi. I have a workflow where my first Action is a Javascript code step. I’m attempting to set a optionID variable using context.item.data[‘ColorID’] from a collection item.
The code step works properly when I test the action independently, however, upon testing the workflow as a whole, I receive a TypeError: cannot read properties of undefined (reading ‘data’).
If I remove the context.item.data and hardcode a value, the workflow works as expected. So, it seems to me there’s an issue when the code tries to read that context.item.data.
Am i missing something here or improperly using this?
Thanks!
I’m not at a computer to try this … but try context.item.data.ColorID
I am from my phone now but from the last picture it seems like context.item
is undefined
. Double check what is the correct path to access the item data. You should be able to click on ‘colorID’ (first picture) to insert the right path automatically.
Thanks for the input, guys.
What you see in the screenshot (context.item.data[‘colorID’]) is what I get when I click the colorID tag under item.data to insert it. i.e. I did not type that in manually.
When testing the action on its own, it is working correctly with the code you see in the screenshot. It’s only when I test the workflow as a whole that it fails due to item.data being undefined.
I tried with a capital “C” to no avail as well.
Is there any input that you can fill in the ui when you test the complete workflow, like test input data? does it work in preview mode when you click the button?
I’ve tested by removing the context.item.data and inputting a hardcoded value for that variable in my code, which works as expected when testing the full workflow.
My original code (with context.item.data) does not work in preview mode or when I test the workflow as a whole…it does work when I test the action individually.
For some additional context: this workflow is supposed to run on click when a user clicks one of the color swatch icons in the screenshot.
Each icon is a Collection Item within my color swatch Collection List.
I thought perhaps my issue was that I put the workflow on the icon itself, instead of the Collection Item element. In testing, however, I am getting the same result when i put the workflow on the collection item element. that context.item.data is being read as undefined when the workflow is tested as a whole.
I tried a similar setup and I actually get the same error. The property item
is in the context
when the single step is tested but not when the global workflow is tested. But in my case the workflow is working properly in preview mode.
If you need to test your whole workflow instead of the single steps a solution can be to create a global workflow.
- create a global workflow and give it a name
- add a Parameter “colorID” of type Text
- copy your steps into the global workflow (click on the three dots to copy the step)
- change your js action code to use the parameter instead of the item (the parameter is accessible in the tab between formulas and collections)
- replace the workflow on the icon with a single action that run the global workflow passing the colorID from the item
In this way the global workflow will let you set the parameters you want to use to test it and you will be able to try your full logic in different cases.
1 Like
Thanks for all this…super helpful and I will definitely try this approach down the road.
I was able to get the workflow working in preview mode - turns out I had another small issue with a later workflow action that was preventing it from running in preview mode.
So, kind of annoying that I can’t test the workflow as a whole outside of preview mode, but I was able to workaround it.
Thanks for the help, guys!