Aller au contenu principal

WF & VSW: Can I bind to a display form in an asynchronous child workflow using workflow.run?

Répondu

Commentaires

5 commentaires

  • Gareth Evans

    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
  • Zack Robison

    I found an answer, and it turned out to be blissfully simple!  It only required four activities.

    1. 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.
    2. Bind to that form in the outside workflow using the Get App Data activity.
    3. 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.
    4. 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
  • Gareth Evans

    Very cool Zack Robison! Thanks for sharing your findings, I'll keep this in my back pocket.

    0
  • Zack Robison

    Thank you.  And it only took me <redacted> hours to figure out 😎.

    0
  • Emil Solbakken

    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.