How to access a workflow value in custom React Form Element code
I currently have a “Get Portal User” activity feeding into a “Create Value” activity that holds a string value containing a username. The resulting value of interest is $value1.result. Connected below is a “Display Form” which contains a custom React form element used to display a website. In my React website, I want to access this string to display different content depending on the user.
How can I access the value of $value1.result to use in my custom React code as a variable? In workflow, I have attempted to explore the “load” event in my custom form element with no leads on how to access it from my React code.
Thanks in advance.
-
Typically you are going to need to use the Set Form Element Property activity in the load event of your custom form element.
Consider the Star Rating Custom Form Element implemented here: https://developers.vertigisstudio.com/docs/workflow/tutorial-web-implement-star-rating-form-element. The props of this custom component look like this:
interface StarRatingProps extends FormElementProps<number> {}
That <number> means that the “value” prop is a number, so this form element accepts a numeric value.
To set the value prop at runtime we would use the Set Form Element Property activity with:
- Property Name: value
- Property Value: =$value1.result
If the built-in “value” prop is not appropriate for your custom React component feel free to add whatever props you expect, for example: username: string;. Then when using Set Form Element Property set the Property Name to be the name of the prop you want to assign.
1 -
Hi Ryan,
This solution worked, thank you for your help. Cheers
0 -
Glad you are up and running.
I've added a section to the docs on how to set the value (or any other prop) of a custom form element at runtime here https://developers.vertigisstudio.com/docs/workflow/tutorial-web-implement-star-rating-form-element#set-the-form-elements-value-at-runtime.
1
Du måste logga in om du vill lämna en kommentar.
Kommentarer
3 kommentarer