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
Thank you Jonathan.
Great post from a great blog by a great guy :).
Amer
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
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
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.
Hi Jonathan, great post!
But how can I approve/reject an workflow item already submitted using x++?
WorkflowWorkItemActionManager::dispatchWorkItemAction( workItem, _comments, to_user, workItemActionType, _menu_item, false);
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.
We have similar requirement, could you please suggest is it possible? Thank you.
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!
They have renamed Templates to Types in AX2012
On Wed, Mar 19, 2014 at 11:41 PM, Dynamics AX Workflow Wanderings wrote:
>
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!
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
there is no method named “activateFromWorkflowTemplate” instead “activateFromWorkflowType” is there what to do for auto submit of generated record?
thanks.