VMware Cloud Community
donakhan
Contributor
Contributor

How to tell is workflow initiated from Presentation UI vs REST client

I'm trying to determine in a workflow JS schema if the workflow was initiated from the UI vs being launched via a REST request. I could certainly find some way to do this based on perhaps an attribute that only gets set when the UI runs but I'm wondering if there is a JS builtin to tell if the UI was run when the workflow launches.

Reply
0 Kudos
4 Replies
iiliev
VMware Employee
VMware Employee

I don't think there is such JS builtin function. Usually, such distinction is not required.

Out of curiosity, why do you need it, and what you would do differently depending on the way the workflow was started?

Reply
0 Kudos
donakhan
Contributor
Contributor

I have  a workflow that modifies existing values of an object using prepopulated fields for input data. When using the UI the user can delete the data in the field meaning that the contents are meant to be erased, however when using the REST API the absence of the field means that the field is not to be modified. In the UI I was a null value to mean erase while in REST it means do not modify. I'll find another approach to solve the issue. I was hoping for some standard way to tell.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee

Well, when starting the workflow via REST  API call, you can pass additional parameter(s) in 'token' scope, and then in the workflow scripting you can access them using ExecutionContext. So this way you can pass some flag indicating that origin of the workflow execution is a manual REST API call.

But I don't like this hidden change of the behavior. Why don't you add a normal boolean parameter asking the user to explicitly choose whether the missing stuff should be erased or not modified?

donakhan
Contributor
Contributor

I'll look into this. I don't like that the user has to explicitly chose between erase or modify. However I think I found a solution. Seems like a cleared form field is still an empty string vs null if the parameter is not passed in. I can just use that test. Thanks for the info.

Reply
0 Kudos