- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2024 11:07 PM
I have a few questions here:
1) Can I create a flow without a trigger defined? I want to be able to call it on demand from a script.
2) How can I call a flow from a script include?
3) On the beginning of the flow, I want to know who the logged in user is, how do I get the logged in user?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2024 11:53 PM
Hi @begsa
- No, Flows need a trigger. But you can use Subflows instead. They can be invoked from a script without a trigger.
- It is extensively explained at https://developer.servicenow.com/dev.do#!/learn/learning-plans/vancouver/servicenow_application_deve...
- You can use a Flow variable and assign the respective value to that Flow variable via inline script:
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2024 01:43 AM
1) Can I create a flow without a trigger defined? I want to be able to call it on demand from a script. - Yes, you can create a flow without a trigger defined. This is known as a subflow in ServiceNow. Subflows can be called from other flows or scripts. 2) How can I call a flow from a script include? - You can call a flow from a script include using the FlowAPI class. Here is a sample code: javascript var flow = new sn_fd.FlowAPI(); var inputs = {}; inputs['input1'] = 'value1'; // replace with your actual inputs var flowName = 'x_snc_my_namespace.my_flow'; // replace with your actual flow name flow.startFlow(flowName, null, null, inputs); 3) On the beginning of the flow, I want to know who the logged in user is, how do I get the logged in user? - You can get the logged in user using the gs.getUserID() method in a script. Here is a sample code: javascript var userID = gs.getUserID(); - In a flow, you can use the Current User data pill from the Flow Context data pills category.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-05-2024 11:53 PM
Hi @begsa
- No, Flows need a trigger. But you can use Subflows instead. They can be invoked from a script without a trigger.
- It is extensively explained at https://developer.servicenow.com/dev.do#!/learn/learning-plans/vancouver/servicenow_application_deve...
- You can use a Flow variable and assign the respective value to that Flow variable via inline script:
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2024 01:43 AM
1) Can I create a flow without a trigger defined? I want to be able to call it on demand from a script. - Yes, you can create a flow without a trigger defined. This is known as a subflow in ServiceNow. Subflows can be called from other flows or scripts. 2) How can I call a flow from a script include? - You can call a flow from a script include using the FlowAPI class. Here is a sample code: javascript var flow = new sn_fd.FlowAPI(); var inputs = {}; inputs['input1'] = 'value1'; // replace with your actual inputs var flowName = 'x_snc_my_namespace.my_flow'; // replace with your actual flow name flow.startFlow(flowName, null, null, inputs); 3) On the beginning of the flow, I want to know who the logged in user is, how do I get the logged in user? - You can get the logged in user using the gs.getUserID() method in a script. Here is a sample code: javascript var userID = gs.getUserID(); - In a flow, you can use the Current User data pill from the Flow Context data pills category.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2024 03:41 AM
Hi @begsa
For the 1st pint, A flow minimum requires a Trigger and a Action.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 06:52 PM
Thank you for the replies, having the subflow instead of the flow helped.
The flow variables were not setting properly with the logged in user and the gs.getUserID() kept getting the system user the subflow was running as instead of the logged in user. I also made the subflow client callable since I wanted to access this from a widget and set the ACL's as well.
I was able to call the flow from a background script and a script include as well with the code snippet.