cancel
Showing results for 
Search instead for 
Did you mean: 
andymcv
Nintex Newbie

How To Save Workflow History To Document Properties?

Jump to solution

Hi Gang

We are using SharePoint and Nintex versions 2013.  I have a workflow that allows a document to be reviewed and approved by a number of employees.  When the document is fully approved I would like to save the workflow (approval) history somehow to the document properties.  I have no way to change the setting that removes the regular workflow history after 60 days.  So I'm stuck with trying to save it off for audit purposes.  For us we need to have this info for a number of years.  Can someone help me figure out how to save the workflow history so that we'll always have it for audit purposes for a document.

Best Regards,

Andy

Labels: (2)
0 Kudos
Reply
17 Replies
eiben
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Hi,

you could query the Workflow History List to get all history entries and then write them to a sharepoint column. The trick is, that the History-List is a hidden list and therefor not visible in the "Query List" action.

But if you use the CAML editor you could "hand-craft" a CAML-statement to retrieve all associated history list entries.

Of course you need to insert the name of the History-List you associated with the current workflow. Then you just have to query the internal fieldname "WorkflowInstance" for the value of the current workflow instance. (Attention: you need to have two "{" at the beginning and two "}" at the end!)

I retrieved the Description (that's the actual message logged to the history log) into a collection.

I then joined all collection-entries into a string, separated by a "newline".

You can now write this into a sharepoint column, which could be mapped to a document or just keep it in the column.

Reply
andymcv
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Ok Henning, I think I have this working!

I've now created the following CAML code.  My last question to this is how would I get the User ID, Date Occurred, Outcome, and Description all together on their own line for each approval showing in a single item field (for the approved document in this case)?

Something like

Josh Francisco - 8/15/2017 7:47 PM - Approved - (Josh Fransisco) This is my approval comment.

Amy Zeller - 8/15/2017 5:22 PM - Approved - (Amy Zeller) This looks great!

Sarah Collison - 8/15/2017 2:13 PM - Approved - (Sarah Collison) Ok.

<Query>
  <Lists>
    <List Title="NintexWorkflowHistory" />
  </Lists>
  <ViewFields>
    <FieldRef Name="User ID" />
    <FieldRef Name="Date Occurred" />
    <FieldRef Name="Outcome" />
    <FieldRef Name="Description" />
  </ViewFields>
  <Where>
    <And>
      <Eq>
<FieldRef Name="WorkflowInstance" />
<Value Type="Text">{Common:WorkflowInstanceID}</Value>
</Eq>
      <Eq>
<FieldRef Name="Outcome" />
<Value Type="Text">Approved</Value>
</Eq>
    </And>
  </Where>
</Query>

0 Kudos
Reply
eiben
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Awesome! You will have to change "User ID" to just "User" and "Date Occured" to "Occured" as the CAML will need to reference the interanl field names, not the display names (hint: you can test the query in the "query list" action by pressing the "run now" button!)

Well, as shown in my original reply I store the result in a collection. You'll need to have four collections, one for each field.

Instead of joining the elements of the collection you need to iterate over one of the collections, remember the index of the current iteration and retrieve the corresponding values from the other collections. To retrieve the values from the collection you'll need some "temporary" variables - I like to call them "varCurrent[Fieldname]". So this is a set of variables you might need:

You will want to wire the collections in the query list action:

To iterate over your results you need the for-each action:

Next you have to retrieve the description, date and outcome using the index like this:

Finally you can build-up a string out of these values:

Reply
andymcv
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Hi Henning

I'm close but I'm not getting any data in my variables (e.g. varCurrentDescription) from the collections (e.g. varColDescriptions). 

I set up the variables as you've recommended.

For testing, I run the Query List (in the "Run Now" using an existing WorkflowInstanceID) it works and I get data as below. 

When I run the real workflow I put "{Common:WorkflowInstanceID}" into the value for WorkflowInstance.

The next action as you've suggested creates the For Each loop using the UserID collection. 

The first action in the For Each Loop pulls out the description from it's collection.

For testing I put this Set Field action next.  Unfortunately when I run the workflow nothing is put into the Test field.  So that leads me to think there is nothing in the collection.

Any ideas on your side would be greatly appreciated!!


Best Regards,
Andy

0 Kudos
Reply
eiben
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Is just the Description empty or are all collections empty?

0 Kudos
Reply
andymcv
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

I'm not sure how to check to see if the collections are empty.  I assume that they are empty because I'm not getting anything in the end varHistory variable that should include everything.  I wish I could check to see if the CAML query is returning anything.

0 Kudos
Reply
eiben
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

OK, make sure that you put {Common:WorkflowInstanceID} in double "{" and "}" like this {{Common:WorkflowInstanceID}}. The inner "{" are being replaced and the outer are there - because it's supposed to be a guid

Reply
andymcv
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Hmmm... I changed it to the following with the 2 curly brackets and I get the same result.  Seemingly no errors but no data as well.  It all looks like it should work.

<FieldRef Name="WorkflowInstance" />
<Value Type="Text">{{Common:WorkflowInstanceID}}</Value>

0 Kudos
Reply
eiben
Nintex Newbie

Re: How To Save Workflow History To Document Properties?

Jump to solution

Can you enable verbose Logging für the workflow? You can enable this in the workflow settings. And you will also need to enable this in the central administration in the global settings of nintex workflow.

After enabling this, you can inspect the values in the workflow history by clicking on the workflow actions.

0 Kudos
Reply