- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 02:33 AM
Hello,
Can anyone please help me on this below requirment.
I have created a new state as Draft for change request.Created new ui action'submit request'.this button will be visible on all type change request like emergency standard and normal and the when the state is in draft.
Once click on the ui action 'submit request' the normal workflow that has been defined for all the type request will start.
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 02:56 AM
Hi,
You can use this script to trigger workflow from script
Remember UI Action should be server side
triggerWorkflow();
function triggerWorkflow(){
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName('give the workflow name'), current, 'update');
}
I would insist if possible make the workflow trigger based on the proper condition
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
‎09-18-2020 03:16 AM
Hi,
so you want to trigger which workflow?
are you saying based on the change type you want to trigger that particular workflow?
if yes then try this
Ensure you give valid choice values and valid workflow names
triggerWorkflow();
function triggerWorkflow(){
var type = current.type;
var workflowName = '';
if(type == 'emergency'){
workflowName = 'emergencyWorkflowName';
}
if(type == 'normal'){
workflowName = 'normalWorkflowName';
}
if(type == 'standard'){
workflowName = 'standardWorkflow';
}
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName(workflowName), current, 'update');
}
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-09-2021 09:36 PM
Hello Ankur,
I created the UI action for triggering the workflow using the above script .But I am not able to trigger . when I clicked the button its getting refreshed. And its showing the error like first select the table .So please help me .
PFA screenshots.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-09-2021 10:15 PM
Your UI action should be server side
Client checkbox - uncheck
Onclick - remove function
Script - keep as it is
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 04:27 AM
Hello Ankur,
It is triggering the workflow.If i am saving the record instead of clicking the UI action'submit the request' the state is getting changed to new.After saving the record it should stay in draft state.
triggerWorkflow();
function triggerWorkflow(){
var type = current.type;
var workflowName = '';
if(type == 'Emergency'){
workflowName = 'Emergency Change';
}
if(type == 'normal'){
workflowName = 'normalChange';
}
if(type == 'standard'){
workflowName = 'Standard Change';
}
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName(workflowName), current, 'update');
}
if(typeof window == 'undefined')
saveRecordAndReload();
function saveRecordAndReload() {
current.state==-7;//draft state value
current.update();
action.setRedirectURL(current);
}
But this is not working to save the record in draft state.Can you please let me know where i am doing mistake.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2020 05:45 AM
I assume you want once UI action is clicked the workflow should trigger and state should change to -7
please update code as below
triggerWorkflow();
function triggerWorkflow(){
var type = current.type;
var workflowName = '';
if(type == 'Emergency'){
workflowName = 'Emergency Change';
}
if(type == 'normal'){
workflowName = 'normalChange';
}
if(type == 'standard'){
workflowName = 'Standard Change';
}
var wf1 = new Workflow();
wf1.startFlow(wf1.getWorkflowFromName(workflowName), current, 'update');
current.state = -7;//draft state value
current.update();
action.setRedirectURL(current);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader