- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 12:01 AM
Hi Team,
I have a workflow that is running on a schedule. I wanted to check if I can run that workflow from background script on ad-hoc without modifying the workflow?
Please help me with a script as I need to test few things by running the workflow on ad-hoc basis
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 12:30 AM
Hi,
yes few updates
just give the workflow name as well
var gr = new GlideRecord('table');
gr.addQuery('sys_id','sys id of a record');
gr.query();
if(gr.next())
{
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');
}
For insertion
var gr = new GlideRecord('table');
gr.initialize();
gr.insert();
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 12:08 AM
Hi,
sample script below for running workflow from background
ensure you use GlideRecord object of correct table
var gr = new GlideRecord('schedule table');
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 12:26 AM
var gr = new GlideRecord('schedule table');
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');
Do I need to update the script to add few lines?
Like
var gr = new GlideRecord('table');
gr.addQuery('sys_id','sys id of a record');
gr.query();
if(gr.next())
{
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 12:27 AM
Also I want to run it for already existing record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 06:29 AM
Hope you are doing good.
Let me know if that answered your question.
If so, please mark my response as ✅ correct & 👍 helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader