Calculated Fields for use in Workflow Conditional statements and Notifications

2 11 2009

Finally i stumbled across something while watching a Microsoft Training video for Dynamics AX Workflow, that I’ve been looking for for ages. The ability to add calculated fields to your workflow documents for use in conditional statements or notifications or for the yellow workflow message bar.  Maybe I’m just overlooked this through my initial learning stages of workflow, but this is huge. A typical example of where one might use this is if you have a purchase requisition with an approval step that you only want to kick off if the requisition’s totalAmountMST() method is greater than 1000. Quite simply, you need to just add a new method to your WorkflowDocument Class which ascribe’s to the following criteria:

1. Be name parm[method]
2. Recieve a tableid param and a recid param
3. Return and Extended Data Type (the EDTs label will appear in your field list)

e.g.

public PurchReqTotalAmountMST parmTotalAmountMST(tableId _tableId, RecId _recId)
{
    PurchReqTable req;
    ;
    select req where req.RecId == _recId;
    return req.totalAmountMST();
}

Once you have done this you should be able to use the field for conditional statements, notifications, help-texts and instructions.

conditional

 

messages

I hope this will be as helpful to you as I know it will be to me.

hat tip: MSDN docs

 

Advertisements

Actions

Information

31 responses

6 01 2010
prav

actually the method for returning the calculated value needs to have 3 parameters -> companyid,tableid,recid.

best regards,
Prav

14 01 2010
Jonathan Halland

Prav, I’ve had a look at your suggestion and I’m not sure if we are running different versions, but within my AX version only the tableid and recid fields are needed for the calculated fields (as per msn docs), the data area as far as i can tell will automatically be done based on the data area from which the record comes from.

15 01 2010
prav

Strange…. I’m using sp1, IND loc, first of all thanks for sharing your knowledge on this topic, it helped me a lot. I followed the procedure mentioned above and while testing the workflow condition i fugured out nothing was happening no error and no ouput, so when i debugged the code i found the line of code that was calling the parameter method of document class (SysExpression->buildXMLDocument->line 112) and this was invoking the method with companyid as a parameter, So i added the parameter and it worked fine.

vl try checking this on a different version..

anyhow thanks a lot..

Best Regards,
Prav

30 04 2010
czanata

i need to calculate the sum of purchase requisitions approved by the user assigned to workflow.
How can i get this user?
i try to use but the class return and always zero value.

can you help me?

3 05 2010
Jonathan

Hi Czanata

When/where in workflow are you wanting to do this check?

5 05 2010
johnny

Hi, great tip!

How do you add a field (not a calculated value) from a table.

i.e. making ProjTable.responsible from the dropdown when configuring the conditions for when a step is to be run. I would like to be able to check if infact the Purchase Requisition.Requisitioner == projtable.responisble;

Any insight would be appreciated!

5 05 2010
Jonathan

Hi Johnny
I would imagine there are a number of ways to do that. Off the top of my head i would create the calculatedfield method above, but name it something like isProjResponsible and return a NoYes enum based on your logic. In your WF configuration you could then just create a condition using that calculated field == Yes

5 05 2010
johnny

Hi again
I’m trying something close;
_______________________________________________________________________
Public ProjResponsible ProjResponsible(TableId _tableid, RecId _recid)
{
ProjTable ProjTable;
PurchReqTable PurchReqTable;
;

Select firstonly * From ProjTable
Where ProjTable.ProjId == PurchReqTable.ProjId
&& PurchReqTable.RecId == _recid;

Return ProjTable.Responsible;
}
____________________________________________________________

however I’m unable to find Project Manager in the drop down menu. When copying and pasting your example easily available form the “root”.

6 05 2010
Jonathan

Hi Johnny.

Add a ‘parm’ prefix to your method e.g. parmProjResponsible(….)
You should now see the option ‘Project Manager’ under your condition builder.

Regards

6 05 2010
johnny

Excellent! I guess my autodidact ways have their limits. I worked it out thanks to your enlightened input.
BTW I also had to add companyid to the method:
Public ProjResponsible parmProjResponsible(Companyid _companyid, Tableid _tableid, RecId _recid)

6 05 2010
johnny

Oh I forgot! thank you!!!!!

22 08 2010
Naresh

Hi,
Could you please help me how to setup notification for each workflow step.i.e If I have one workflwo with 3 steps and assigning to 3 diff users.If first approver approved then i need to notify to the originator saying first approver approved.
We have workflow notification setup but it will send notification after final approval.Please help me.

Thanking you

Regards
Naresh

23 08 2010
Jonathan

Hi Naresh.

Unfortunately I’m unaware of any way of accomplishing this. The notifications are only available to the approval level (i.e. only once all the approval steps have been completed or the workflow has been started) and workflow level, not on the individual steps. You could possibly accomplish this by modifying the standard SysWorkflowEventDispatcher class onStepComplete method. But I would recommend against making system class modifications at all costs.

Regards
Jonathan

23 08 2010
Naresh

Hi Jonnath,
Thanks for reply,really your blog helping lot of people.Thanks for sharing workflow information in your blog.

Thanking you,

regards
Naresh

22 07 2013
Dona

Hi. I have a problem to view a new real field added in Purchasse requisition line (PurchReqLine) in the conditionals statements . If i add a new field in Purchasse requisition (PurchReqTable) i view it automatically.
Can you help me please
Dona

22 07 2013
Jonathan

You need to ensure that your label is unique and you will most likely need to restart your AX client

23 07 2013
Dona

OK I found It. Simply changing the query linked to workflow. I added my fields to the query line because parameter dynamic is false.
Dona

23 07 2013
Jonathan

Thanks Dona for posting that resolution to the issue.

10 09 2014
Priscila

Jonathan, how to create a calculated field to the PurchReqLine and use it in workflow?

Thanks.

10 09 2014
Jonathan

Are you using AX2012 or AX2009 and are you using the PurchReqLine workflow or header workflow?

On Wed, Sep 10, 2014 at 10:58 AM, Dynamics AX Workflow Wanderings wrote:

>

10 09 2014
Priscila

Hi Jonathan,

I am using AX 2012 with header workflow.

10 09 2014
Jonathan

Hi Priscila.

Using the calculated fields as per this article won’t work for you. Even if they did you may get unpredicatable results that cannot be used in conditional statements.

May I ask what your larger goal is?

On Wed, Sep 10, 2014 at 11:05 AM, Dynamics AX Workflow Wanderings wrote:

>

10 09 2014
Priscila

Hi Jonathan,

Actually I want to add a calculated field to Purchase Agreement workflow to add Net Amount for Agreement Line as a condition.

10 09 2014
Jonathan

Line values returned in conditions come as a comma separated string e.g. “1, 2, 3, 4” so trying to do a condition e.g. Where PurchAgreement.Line.LineAmount > 100 wont necessarily work at the values returned will be in format “23, 25, 100, 102”.

Rather create a header calculated field e.g. parmLargestValueLine (returns largest line value) or parmMyCondition (returns true or false). Depending on your needs. What is the rule?

On Wed, Sep 10, 2014 at 11:10 AM, Dynamics AX Workflow Wanderings wrote:

>

10 09 2014
Priscila

Hi Jonathan, thanks for all your reply.

Here is the scenario: Add a condition to Purchase Agreement Workflow when the AgreementLine.NetAmount (the calculated field) > XYZ then a automatic action will be launched.

10 09 2014
Jonathan

Hi

I dont really understand how a header level workflow can be dependant on a line value. Surely your workflow would be dependant on the total header amount

On Wed, Sep 10, 2014 at 11:19 AM, Dynamics AX Workflow Wanderings wrote:

>

10 09 2014
Priscila

Hi Jonathan.

So I cannot add a calculated field to the line?

Thanks

10 04 2015
Owen

Hi Jonathan,

Excellent blog!

In your screenshot when adding the criteria we can see that you can add criteria from either “Purchase Requisition>” or “Workflow>”. I need to add a new computed field to the workflow part if this is possible. I need to expose a property from the position currently assigned to the user who is the owner of the workflow. I am confident I can write the method I need, but I have no idea what class I should add it to in order for it to be exposed here.

If you have any idea where I could start that would be greatly appreciated.

Thanks!

Owen

20 04 2015
Jonathan

Hi Owen.

You could simply add this as a calculated field on the Purchase Requisition Document itself, I’m not 100% certain what class you would need to modify to get it to display under the “workflow” section.

On Fri, Apr 10, 2015 at 10:35 PM, Dynamics AX Workflow Wanderings wrote:

>

17 02 2016
afsar

did you ever work on this issue? https://community.dynamics.com/ax/f/33/p/190426/481772#481772

i want to add this field on workflow right side of expression

-Afsar

17 04 2017
Taskheer

Dear Sir,

How to do multiple Approval in single click in AX 2012?

Please Help me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: