Using GlideFlow in Workspace Client Script?

KB1
ServiceNow Employee
ServiceNow Employee

Hi, 

 

Does anyone know how to use GlideFlow in Workspace Client Script? If it's not possible, what is the alternative to leverage modern capabilities for a basic use case of invoking a Flow Designer Action from a Button on the new Workspaces?

 

The error being received is "SCRIPT:EXEC Error while running Client Script "GlideScopedScript": ReferenceError: GlideFlow is not defined"

 

I'm just doing something like this in "Workspace Client Script":

 

	GlideFlow.startAction('global.myAction', inputs)
		.then(function(execution) {
			return execution.awaitCompletion();
		}, errorResolver)
		.then(function(completion) {
			var status = completion.status;
			// Available Outputs:
			var outputs = completion.outputs;
            g_form.save();

		}, errorResolver());	

 

1 ACCEPTED SOLUTION

Soeren Maucher
Mega Sage

Hello @KB1

I assume with the “Workspace Client Script” you mean the script field in a UI Action for Workspace as shown in the following Screenshot:

SoerenMaucher_0-1677858551585.png

 

I double checked, and while calling the Flow action from the “UI16” client-side UI Action is working, it is not supported by the “Workspace Client Script” (shown in the screenshot). I have implemented this logic multiple times in the past, calling it from the “UI16” backend UI Actions.

However, I quickly created a working example that is calling a Flow Designer Action from a “Button on the new Workspaces”, this time however using Server side script. A nice side effect of this approach is that we can avoid having to create the ACL.

Here are the steps to reproduce:

 

1. Create a Flow action (in my case a simple one that is creating a log entry)

SoerenMaucher_1-1677858551586.png

 


2. Create code snipped for this Flow Action and copy the server side code:SoerenMaucher_2-1677858551588.png

 

 

SoerenMaucher_3-1677858551593.png
3. Create a UI Action with the “Client” option unselected (In my case for the incident table):

SoerenMaucher_4-1677858551594.png

4. Paste the code in the “Script” field

SoerenMaucher_5-1677858551595.png

5. Select the both Workspace form button options so that this UI Action can also be used in Workspace. Here we leave the “Workspace Client Script” field empty, since it will run server side with the previously provided code in the field “Script”
SoerenMaucher_6-1677858551596.png

6. Create a new Workspace (e.g. using App Engine)
SoerenMaucher_7-1677858551606.png

7. In the Preview of a record (in my case incident) we see now the UI Action “Call Flow Action”
SoerenMaucher_8-1677858551610.png

8. After clicking it, we can check the logs and see the corresponding log message created by the Flow Action:
SoerenMaucher_9-1677858551611.png

 

I hope this helped. If yes, I would appreciate if you could mark this answer as "correct solution" or give a thumbs up. Thank you!


Greetings,
Sören

View solution in original post

4 REPLIES 4

Soeren Maucher
Mega Sage

Hello @KB1

in order to make a Flow client callable you will have to create a specific ACL. I have done this multiple times in the past for exactly this use case (Calling a Flow/Subflow from a UI Action),  and can therefore confirm that it is working. 

Here is the official ServiceNow documentation with a step by step instruction on how to achieve this: https://docs.servicenow.com/bundle/utah-build-workflows/page/administer/flow-designer/task/grant-acc...
I hope this helped. If yes, I would appreciate if you could mark this answer as "correct solution" or give a thumbs up. Thank you!
Greetings,
Sören

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I don't think you'll be able to access the GlideFlow api directly from a UI Builder script. You'll either need to create a transform data resource that executes the flow or do a record update that triggers the flow.

Soeren Maucher
Mega Sage

Hello @KB1

I assume with the “Workspace Client Script” you mean the script field in a UI Action for Workspace as shown in the following Screenshot:

SoerenMaucher_0-1677858551585.png

 

I double checked, and while calling the Flow action from the “UI16” client-side UI Action is working, it is not supported by the “Workspace Client Script” (shown in the screenshot). I have implemented this logic multiple times in the past, calling it from the “UI16” backend UI Actions.

However, I quickly created a working example that is calling a Flow Designer Action from a “Button on the new Workspaces”, this time however using Server side script. A nice side effect of this approach is that we can avoid having to create the ACL.

Here are the steps to reproduce:

 

1. Create a Flow action (in my case a simple one that is creating a log entry)

SoerenMaucher_1-1677858551586.png

 


2. Create code snipped for this Flow Action and copy the server side code:SoerenMaucher_2-1677858551588.png

 

 

SoerenMaucher_3-1677858551593.png
3. Create a UI Action with the “Client” option unselected (In my case for the incident table):

SoerenMaucher_4-1677858551594.png

4. Paste the code in the “Script” field

SoerenMaucher_5-1677858551595.png

5. Select the both Workspace form button options so that this UI Action can also be used in Workspace. Here we leave the “Workspace Client Script” field empty, since it will run server side with the previously provided code in the field “Script”
SoerenMaucher_6-1677858551596.png

6. Create a new Workspace (e.g. using App Engine)
SoerenMaucher_7-1677858551606.png

7. In the Preview of a record (in my case incident) we see now the UI Action “Call Flow Action”
SoerenMaucher_8-1677858551610.png

8. After clicking it, we can check the logs and see the corresponding log message created by the Flow Action:
SoerenMaucher_9-1677858551611.png

 

I hope this helped. If yes, I would appreciate if you could mark this answer as "correct solution" or give a thumbs up. Thank you!


Greetings,
Sören

KB1
ServiceNow Employee
ServiceNow Employee

Hey @Soeren Maucher , this worked like a charm! Really appreciate your effort with the description and detailed steps! Thanks for this! Saved a lot of digging around without success.