WF & VSW: Can I bind to a display form in an asynchronous child workflow using workflow.run?
RéponduFor many applications, especially data editing, I like to use a child workflow to take a config, a form, and usually a handful of state variables in order to set form element properties and, especially, to prefill a form.
This works just fine using the synchronous Run Workflow activity, but I'd like to be able to run it asynchronously by calling workflow.run in a Run Command activity. I just don't see the need for the drawing of the form, which takes some time, to sit and wait for all those little mini-workflows to communicate. It's not that these child workflows take a long time (they don't) but it just seems like the better way to go about this to me as I suspect that they could largely all run and do their duty in the DOM while the form element draws (or am I missing something?).
Issue is that I cannot get the Set Form Element Property activities to bind to the form when I do this. I did a little debugging and see that the .form input to those properties is derived from the workflow state, but have not figured out how to get the child workflow to take that form from its parent. I thought that the .target or .instanceId arguments to workflow.run might do the trick, and I tried toying with .commandArgumentInput as well but haven't figured it out yet... the form element activities don't find any forms in the workflow to manipulate. Anyone know the trick?
-
Hi @... interesting question. I'm not aware of a method to do this, though I'm curious to see what this discussion will produce. My initial thought is that two workflows running via workflow.run being asynchronous may produce a race condition whereby the form elements may not necessarily be there in time for the set form element property to do its job, but I'm unsure.
1 -
I found an answer, and it turned out to be blissfully simple! It only required four activities.
- Place the target workflow, the one to be updated, in the app state with Set App Data; it needs to be the entire form object so the Value argument must be e.g. "$form" and not "$form.state". Do this in the load event subworkflow on a form element, you won't need to wait for the entire workflow to render because the $form object is a reference and not a primitive so the value held in the application state will update with the form.
- Bind to that form in the outside workflow using the Get App Data activity.
- Update the desired form property. Use the Forms activities such as Set Form Element Property from the outside workflow with the result of the Get App Data activity with an Element argument like "=$getFormFromAppData.value.state.yourElement". This won't rerender the form but it will still update that form object, as you can see in the developer console. You might be able to use Set Property or Evaluate Expression from other workflows instead.
- Rerender the workflow. Updating workflow element properties does not re-render the form itself, which was my sticking point earlier, but I discovered that forms have an .actor property with a handy .refresh() function to do exactly that! So, after updating any form properties as desired, run an Evaluate Expression activity to call that function, something like "=$getFormFromAppData.value.actor.refresh()".
Voila! I'm not using this for my original use case, I'm just running the necessary child configuration workflows synchronously as needed because they're pretty fast. I have however used this to get forms in sibling workflows to interact with each other, and I'm also using it to bind a Checkbox component in VS Web to a couple of workflows as well. So I now have a checkbox outside of the workflow forms themselves which when checked enables/disables a number of form elements in multiple workflow forms!
I been looking for a way to do this without custom development for a little while, so thought I'd share for anyone else who wants to do the same. I like to think I'm not the only person who's wanted to do something like this, so spread the word if you know of any use cases @....
2 -
Very cool Zack Robison! Thanks for sharing your findings, I'll keep this in my back pocket.
0 -
Thank you. And it only took me <redacted> hours to figure out 😎.
0 -
Thanks Zack Robison, this is very handy!
I'm wondering if it's also possible to trigger a change event in the target form element. I have tried to set the event object of the form before running Evaluate Expression with the .refresh() function, but so far I've not been able to make it work. Guess I can use another external workflow to handle the change event, but would be great if there's a way to change a form element and trigger the associated change event at the same time.
Any ideas?
1
Vous devez vous connecter pour laisser un commentaire.
Commentaires
5 commentaires