How to auto-submit record into workflow

23 06 2010

Just this past week I had a request from one of my blog readers asking how to automatically submit a record into Dynamics AX Workflow without making use of the standard submit button. E.g. on a specific event such as on completion of an RFQ to submit a PR to workflow.

We’ve had this type of request from clients before and its actually relatively simple to accomplish. Check out the PurchReqWorkflow class, method: submit.

You basically only need to execute the following line to kick off any workflow.

Workflow::activateFromWorkflowTemplate( 
this.parmWorkflowTemplateName(), 
purchReqTable.RecId, 
this.parmWorkflowComment(), 
activatingFromWeb, 
SysCompanyUserInfo::emplId2UserId(purchReqTable.Requisitioner));

Adapted for your auto-submission and placed in the relevant section of code, one would use something like the following:

Workflow::activateFromWorkflowTemplate(‘PurchReqApproval’, //Template name
purchReqTable.RecId, //Record id of the document that you are submitting,
‘Auto-Submitted into workflow’, //A comment for the workflow history to know something about how this was submitted,
false, //This document wasn't submitted from the web,
Curuserid()); // The user who should become the workflow originator 

I you find this useful.

Happy Daxing

Jonathan


Actions

Information

14 responses

18 07 2010
Amer

Thank you Jonathan.

Great post from a great blog by a great guy :).

Amer

26 09 2011
Bang Im

Hi Jonathan,

Thanks for the post here, very useful.. Just a quick question, if I have setup the workflow submission condition(i.e. the Set condition for use box in the workflow configuration), will this method honor that condition before submitting the workflow?

Thanks,

Bang Im

27 09 2011
Jonathan

I haven’t tested that yet. But I would guess that it won’t as you are forcing a specific template. However i’m not sure what would happen if you have multiple configurations for the same template all with activation conditions.

Sent from my iPad

1 10 2011
Bang Im

Thanks for the reply, Jonathan. It didn’t seem to validate that condition, so I ended up coding the condition in the X++ logic itself before submitting the workflow.

2 05 2012
Edvandro Santos

Hi Jonathan, great post!

But how can I approve/reject an workflow item already submitted using x++?

3 05 2012
Jonathan

WorkflowWorkItemActionManager::dispatchWorkItemAction( workItem, _comments, to_user, workItemActionType, _menu_item, false);

20 01 2014
Md.Samiu

Hi Jonathan,
I need to submit multiple records for workflow and approve or reject multiple workitem at the same time. is that possible to do.

28 05 2014
Jason

We have similar requirement, could you please suggest is it possible? Thank you.

19 03 2014
yercar

Hi Jonathan, do you know what is the process for approve in Ax 2012? don’t exist the method activateFromWorkflowTemplate, only exist activateFromWorkflowType.
Thank you!

20 03 2014
Jonathan

They have renamed Templates to Types in AX2012

On Wed, Mar 19, 2014 at 11:41 PM, Dynamics AX Workflow Wanderings wrote:

>

19 12 2014
Celine

Hi Jonathan,

I try to write the code in job and run it, but there is no respond in the PR. The submit button still there. Do you know why?

Thanks!

14 01 2015
Jonathan

Hi Celine. You may need to just review the code behind your PR Submit Menu item. There may be code that changes the PR status to “Submitted” you will then need to do this status change in your job as well.

Regards
Jonathan

3 06 2016
taral

there is no method named “activateFromWorkflowTemplate” instead “activateFromWorkflowType” is there what to do for auto submit of generated record?

5 12 2016
guvensahin

thanks.

Leave a comment