Workflow Configuration Displays Error Icon despite being valid

13 02 2018

I’ve recently found a scenario where my workflow configuration has an “invalid” icon next to the workflow configuration, this all despite the latest version being fully validated.

unnamed.png

Tracing back the issue it seems that Microsoft displays the “valid/invalid” icon based on the latest workflow version sorted by workflow version “RecId” (See Table: WorkflowTable.validIcon).

So searching the workflow version Table I found an old invalid workflow configuration version (based on modifiedDateTime) that has an out of sync (i.e. newer) RecId than the actual newest versions. Deleting this record resolved the issue.

There should be no issues deleting this invalid version as actual workflow instances can’t be created against invalid versions.

I think the way the icons are displayed is a bug in AX, but so far doesn’t appear to affect too much.

 





Determine if a document has an outstanding task.

20 05 2015

In AX2009 you used to have two different status for assigned Purchase Requisitions in workflow, namely: “Pending Completion” and “Pending Approval”. Unfortunately in AX2012 this has become simply “In Review” to signify it being in workflow. This allows a more flexible approach to the ordering and reuse of elements in workflow. However it does not provide a clear way to distinguish where the Purchase Requisition is currently in the workflow process especially whether or not the item is currently assigned as a task or an approval.

The code below provides the X++ select statement to determine whether a document in workflow has at least one pending Task based workitem linked to it.

public display NoYes isTask()
{
  WorkflowWorkItemTable workflowWorkItemTable;
  WorkflowElementTable workflowElementTable;
  select firstonly ElementId from workflowWorkItemTable
    where workflowWorkItemTable.RefTableId == this.TableId &&
    workflowWorkItemTable.RefRecId == this.RecId &&
    workflowWorkItemTable.Status == WorkflowWorkItemStatus::Pending
    join ElementId, ElementType from workflowElementTable
    where workflowElementTable.ElementId == workflowWorkItemTable.ElementId &&
    workflowElementTable.ElementType == WorkflowElementType::Task;
  return (workflowWorkItemTable.RecId == 0) ? NoYes::No : NoYes::Yes;
}

Note: If you’re using line level workflows or parallel branches you may not be guaranteed that the result is what you are logically looking for. It will simply return if there is at least one pending task workitem linked.

This post was inspired by forum question: https://community.dynamics.com/ax/f/33/t/161105





Workflow Types in AX 2012

22 01 2015

Looking for a list of Workflow Types (Templates) available in AX 2012: https://technet.microsoft.com/en-us/library/dd362043.aspx





Mass Resume Line Workflows

14 11 2014

Orginally from my new blog: www.exploreax.com

http://www.exploreax.com/blog/blog/2014/11/07/mass-resume-line-workflows/

<strong>Challenge/Problem</strong>: Many line level workflows that need to be resumed.

<strong>Description</strong>: Sometimes due to data or setups one may have numerous line level workflows failing and entering a “Stopped” state. This may be a result of calendars that do not have enough dates created, users who have been disabled etc… If the workflows were header level, it is easy enough to select all in the Workflow History form and click resume, however on line level workflows one needs to view each line level workflow individually and resume them.

<strong>Solution</strong>: The following job can be used to perform mass resume on stopped workflows. You can adapt the SQL to limit to certain documents or document types of necessary.
<pre>static void resumeStoppedWorkflows(Args _args)
{
WorkflowTrackinStatusTable tracking;
int i, j;
while select tracking where tracking.TrackingStatus == WorkflowTrackingStatus::Faulted
&amp;&amp; tracking.WorkflowType == WorkflowTrackingStatusWorkflowType::DependentSubworkflow
{
try {
Workflow::resumeWorkflow(tracking.CorrelationId, “Auto-resumed”);
i++;
}
catch (Exception::Error)
{
//Some may not be able to be resumed but we dont want to stop the process
j++
}
}
info(strfmt(“%1 workflows resumed, %2 workflows could not be resumed”));
}
</pre>





New Blog: Explore Ax.com

24 07 2014

Hi All.

compass-1I have decided to start a new blog to run alongside workflowax.wordpress.com where I can capture some of the daily tips and tricks that I’m finding in AX 2012, without polluting this workflow dedicated blog. Please feel free to visit it, subscribe to it, comment on it, like it, share it etc over at http://www.exploreax.com

For the moment its very basic but will hopefully get some nice new features in the coming weeks.

Kind Regards





Deleting a workflow Instance in Microsoft Dynamics AX 2012

22 05 2014

Deleting a workflow Instance in Microsoft Dynamics AX 2012

I’ve been wanting to write a tutorial explaining the tables involved in a workflow and how to delete an instance if necessary (e.g. when a major fault or data inconsistency occurs), however it seems Colin’s Dynamics AX 2012 blog beat me to it and he did a superb job at that, check it out here





AX2012 – On Reassign: Failed to create a session

23 01 2014

When trying to reassign a record via workflow history in AX2012 we received the error: Failed to create session; confirm that the user has the proper privileges to log in to Microsoft Dynamics.

Screen Shot 2014-01-23 at 2.31.28 PM

The cause of our problem was a faulty CIL. We performed a full CIL compile, restarted AX and then were then able to perform the re-assign





Subworkflow Tutorial

13 01 2014

Since the launch of Dynamics AX 2012 I’ve been amazed at the amount of really good blogs that have started springing up. One such blog is Collin’s Dynamics AX2012 blog. After finding a whole load of question on Subworkflows in Dynamics AX, I considered writing up an article, but found a his tutorial very way more helpful than I could ever be, so please pay his site a visit!

Collin’s Dynamics AX2012 Blog – Subworkflows





JSON in Dynamics AX – Advanced example #1 (Basic Auth)

11 11 2013

After my previous post on using JSON in Dynamics AX2012 I have received a number of requests for some slightly more advanced examples. I will attempt over the next couple of weeks to provide some.

Today I will cover the use of Basic http authentication. There are a couple of non-intuitive tricks that one needs to use to get it to work.
Before performing any direct requests as per our previous example you will need to make some modifications to the headers in your RetailRequestWeb object.

The first header modification is to add the “Authorization: Basic ” header. You can do so by building up the header string as follows

System.Text.Encoding ascii;
str credentials;
credentials = "myusername:mypassword";
//N.B. Encode the credentials before adding them to your headers otherwise you will receive 403 unauthorized errors
ascii = System.Text.Encoding::get_ASCII();
credentials = System.Convert::ToBase64String(ascii.GetBytes(credentials));
//Combine header instruction and encoded credentials
request.parmHeader("Authorization: Basic "+credentials);

The second modification you need to make is set the request content type to “application/json” without this you may receive 403 unauthorized errors. The retails API allows you to set the content type easily by using the parmContentType method on your RetailRequestWeb object.

request.parmContentType("application/json");

Finally the full example of constructing your json request ready for use:

RetailWebRequest request;
System.Text.Encoding ascii;
str credentials;

request = RetailWebRequest::newUrl(_url);
credentials = "myusername:mypassword";
ascii = System.Text.Encoding::get_ASCII();
credentials = System.Convert::ToBase64String(ascii.GetBytes(credentials));
request.parmHeader("Authorization: Basic "+credentials);
request.parmContentType("application/json");




Using JSON in Dynamics AX

22 10 2013

I’ve recently had a requirement to integrate an external system (Toggl http://www.toggl.com) with Dynamics AX 2012’s Timesheet system. However the external system only provided a JSON API which isn’t supported natively by the Dynamics AX AIF system.  After some research and trial and error (using various DLL’s) I eventually stumbled across some really useful classes provided by the Retail module in Dynamics AX2012. These classes (although named “Retail…”) provide a really easy and elegant JSON interaction for any use. Here is a very basic code sample of how to consume JSON using these classes in Dynamics AX 2012.

 

static void myJob(Args _args)
{ 
    RetailWebRequest request; 
    RetailWebResponse response; 
    str rawResponse, value; 
    Map data; 
    RetailCommonWebAPI webApi = RetailCommonWebAPI::construct(); 
    request = RetailWebRequest::newUrl("http://mysite.com/jsonaction"); 
    response = webApi.getResponse(request); 
    rawResponse = response.parmData(); 
    data = RetailCommonWebAPI::getMapFromJsonString(rawResponse); 
    value = data.lookup("elementname"); 
    info(strFmt("Element name: %1",value)); 
}

If you are interested in some more advanced examples of using JSON in AX (e.g. using authentication, retrieving subsets of info or arrays)  or doing some of your own integration into Toggl timekeeping please let me know and I’ll post some more info.