Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Cheyenne1
Kilo Guru

Yes you can. This thread may help https://community.servicenow.com/community?id=community_question&sys_id=af22db21db101fc01dcaf3231f96191d 

Hi, 

Thank you for replying back.

I can't seem to get it to trigger, do I need to add a condition?  The only condition I need is if the button is clicked.  That is the only condition.

How would I add that condition in the code that I provided above?

Okay, you almost there. Just remove the additional parameters in startFlow function. If this doesnt work, then check if your workflow runs when you insert or update a record or by some other means to make sure your workflow is health. 

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

startWorkflow(id);

function startWorkflow(id) {

  var w = new Workflow();

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

}

 

Hi,

It didn't work.  I need the workflow to run because I have a UI Action button on my Catalog Task list and when I hit the button the records that are selected, I need the record information to pass to the workflow so that I can use Powershell to export the information to an excel csv.

So it does not need to trigger the workflow on insert or update.  So I set the condition on my workflow to Run on the sys_id of the UI Action button, but that didn't work.

Am I missing something?

find_real_file.png