- 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-29-2020 10:35 PM
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
- 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:10 AM
Hi Servicenow User,
You have to mention the gliderecord object of the record whose workflow you wan't to start
Replace the current with the glidercord objec.
var w = new Workflow();
var context = w.startFlow(id, current, current.operation(), getVars());
In stead of current you can give glide record: gr (it must be glide record)
id: The sys_id of the workflow to start. This sys_id refers to table wf_workflow.
operation: insert or update
Mark helpful and correct if it helps.
Thanks,
CB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2020 10:58 PM
Hi
You can use below script
var gr = new GlideRecord('your_table');
gr.addQuery('sys_id','sys_id of your record');
gr.query();
if(gr.next())
{
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('your workflow name'), gr, 'insert');
}
// To insert
var gr = new GlideRecord('your_table');
gr.initialize();
gr.insert();
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr, 'insert');
// To update
var gr1 = new GlideRecord('your_table');
gr1.addQuery('sys_id', sys_id of your record);
gr1.query();
if(gr1.next())
{
var wflw = new Workflow();
wflw.startFlow(wflw.getWorkflowFromName('give the workflow name'), gr1, 'update');
}
Mark ✅ Correct if my answer solves your issue and also mark 👍 Helpful if you find my response worthy.
Thanks & Regards
Himanshu Dubey