Trigger workflow from UI Action Button

Dazler
Mega Sage

Hi,

Can you trigger a workflow from a UI Action button? Or do I have to create a business rule to trigger the workflow?

I found this and added it to the UI Action button, but it is not working.

var id = '12345647891023456789123456789'; //sys_id of workflow

startWorkflow(id);

function startWorkflow(id) {

var w = new Workflow();

var context = w.startFlow(id, current, current.operation(),getVars());

}

 

I am still quite new to ServiceNow and I am a fast learner.  Any assistance would be greatly appreciated.

19 REPLIES 19

This is a screenshot of my Catalog Task where the UI Action Button is located.  Once I selected the records I want to export then those are the information I need to pull.

find_real_file.png

 

Screenshot of my workflow

find_real_file.png

 

Screenshot of my UI Action.  I am unsure if I am doing the script correctly.

find_real_file.png

 

Here is the code:

function getExportlist(){
	
var taskList = g_list.getChecked().toString();
	
if(taskList){
     
  
return false;  //Abort submission
}

gsftSubmit(null, g_list.getChecked(), 'wf_ExporttoCSV'); //MUST call the 'Action name' set in this UI Action
}

if(typeof window == 'undefined')
startWorkflow();

function startWorkflow(){
var wf = new GlideRecord("wf_workflow");
wf.addQuery("name", gs.getProperty("Catalog Task Export CSV")); //Define your workflow name in the property
wf.query();
wf.next();
var wflw = new Workflow(); 
wflw.startFlow(wf.getValue('sys_id'), current, current.operation());
}

Could you please let me know the requirement here? 

The requirement:

1.  On the catalog task list, I select the records that I want to export to csv through workflow.  Once I click the export to csv button, then I grab the below information from the selected records and trigger the Workflow to Run

RITM for catalog task ticket

Catalog Task Ticket Number

Short Description (the tickets are something like this: "eMatrix (Esther Mateen)") - will need to pull only the name between the parentheses and the "eMatrix" separately.

Once I pull the name then I can query the sys_user table to get the below information.

Employee User ID

Employee Email

Firstname

Lastname

The UI Action connects to the sc_task table and then I would have to pull the user information from the sys_user table.

 

2. I pull in the above information to a workflow and then I use a PowerShell Activity to export to an Excel CSV.

 

This will be beneficial for my team so that we do not have to manually filled out the excel sheet so that we can use an external software that we use to do the account creation for our outside websites.

Hi Chani,

Are you able to help me with this?

We have to pass HTML element as second parameter in gsftSubmit() but you are passing string which is a list of sys ids selected.

 

Please perform these different ways and let me know:

Way 1: Uncheck Client in UI Action - check whether workflow has been triggered or not. or write only server side code

If we want both client side code and server side code to run then 

Way 2: I presume we cant use gsftSubmit for lists, however lets check it like this by passing second parameter as RP.getControl() or document.getElementById('sc_req_item_list') - Please let me know the result of this

 

Way 3: If Way 2 didnt work then remove the server side code call Script Include(using GlideAjax) to perform workflow triggering code.

 

Please check whether the workflow has been triggered or not by going to Workflow Contexts.

 

 

Please mark 'Correct' or 'Helpful' if it is so