how to save into a variable and start a process at the same time?

I have a feature where the user clicks a link to run a process in the background and perform some actions. What I want to do is to display a message to the user while the PM is running so they know that something is going on. However, I found out that you can't do any other saves until the onSuccess is run. I want to run the following code.

a!dynamicLink(
showWhen: not(ri!inProgress),
value: true,
saveInto: {
a!save(ri!showMessage, true),
a!startProcess(
processModel: cons!WM_PM_SYNC_HOLDS_DATA,
processParameters: {
siteAcronym: ri!siteAcronym,
siteId: ri!siteId,
writeType: ri!writeType,
user: loggedInUser(),
lastSyncDate: ri!lastSyncDate
},
onSuccess: {
a!save(
ri!processInstance,
fv!processInfo.pp.id
)
},
onError: a!save(ri!error, "error")
),
}
),

In the code above, a!save(ri!showMessage, true) is not executed until the onSuccess() in the starProcess() is run even though it's outside of the startProcess. I've tried chaining the process and without any chaining and that save always waits for the PM on success or onError(). Is there a way to get around this? I know there is other ways like using a process report which is what I'm doing, I just want to know if this scenario is possible.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Unfortunately I don't think you're going to find a very good solution for this without changing up your desired design at least a bit.  One thing you could try is a 2-click approach, which can more gracefully handle certain situations like this where you might otherwise want one click to update the state of the local form in 2 separate ways several moments apart.

    Also I'd point out, in case you can pivot to using a!buttonWidget() instead of a link, the new feature in 21.2 in which you can turn on a "loading indicator", sorta handles this sort of thing inherently.  It doesn't exactly allow you to show a custom message, but it allows you to indicate to your user that activity is going on in the background (up until process chaining breaks).

Reply
  • 0
    Certified Lead Developer

    Unfortunately I don't think you're going to find a very good solution for this without changing up your desired design at least a bit.  One thing you could try is a 2-click approach, which can more gracefully handle certain situations like this where you might otherwise want one click to update the state of the local form in 2 separate ways several moments apart.

    Also I'd point out, in case you can pivot to using a!buttonWidget() instead of a link, the new feature in 21.2 in which you can turn on a "loading indicator", sorta handles this sort of thing inherently.  It doesn't exactly allow you to show a custom message, but it allows you to indicate to your user that activity is going on in the background (up until process chaining breaks).

Children
No Data