none
Using of today's date in flow rule RRS feed

  • Question

  • Hi,

    This is a revival of a previous thread of mine about using today's date or the current date in the FIM portal in a flow rule to stamp an object with the date.  More specifically, add today's date to the description when an object is moved in the AD to another OU.  I had a suggestion of using T4FIM FE, but could not get it running, it is not showing up in the workflow activity picker.  I am using FIM 2010 R2 RC - not sure if this is the reason for T4FIM FE to not work.

    I resorted to another suggestion from other threads to use //Request/CreatedTime but without any success.  What I have done in the workflow is to create a FE activity with a custom expression which looks like this: [//Request/CreatedTime] and have the date flow to a string variable which I use in the synchronization rule to add to the description field.  This produces a warning in the FIM eventlog on the FIM portal server "System.ArgumentException: The parameter for the function is of unknown type:'2012-05-08 09:10'.System.FormatException: Guid should contain 32 digits........".  The FIM request log shows a "postprocessingerror"

    This almost looks like the function is expecting a GUID.  I have tried this with the DateTimeFormat but it produces the same error.  Also tried this with //Request/ExpiredTime - same result. If I add date to it like suggested from yet another tread like [//Request/ExpiredTime]+"T01:00:00.000", the portal accepts it but it fails in the synchronization server with an extension dll-exception stating basically that there is an unknown word starting at 0...

    All I need is an aproximation of the current time, I will even settle for any time on the day the rule is applied!  A few questions:

    1. Should it be possible to //Request/CreatedTime like suggested in other threads and the way I am trying to?

    2. Am I using the //Request/CreatedTime in the right way?

    3. If not, Is there any other way to get an approximate time from the FIM portal, maybe another variable?

    4. Is T4FIM FE suppose to work in FIM 2010 R2 RC?

    Appologies for a lengthy post, any help is much appreciated

    Regards

    Johan Marais

    

    JkM6228

    Wednesday, May 9, 2012 5:08 AM

Answers

  • I built a quick activity like you were doing.. here's the code for it.. it's not in VB, but you can probably get the idea.

    Have two code activities:

    • CalculateDate
    • UpdateWorkflowData

    executing in that order.

    The UI passes two dependency properties:

    • DateFormat - what format you want the time in (i.e. dd MMM yyyy )
    • WorkflowData - the name of the WF dictionary key I store the result in

    Everything works as expected.. I might have to use this in my next class - quick and easy :)

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;

    // FIM
    using Microsoft.ResourceManagement.Workflow.Activities;

    namespace FIM.CustomActivity
    {
        public partial class TimeActivity : SequenceActivity
        {
            public string DateTimeValue;

            #region Dependency Properties

            /// <summary>
            /// The format used to convert from dateTime to String
            /// </summary>
            public static DependencyProperty DateFormatProperty = DependencyProperty.Register("DateFormat", typeof(string), typeof(TimeActivity));
            public string DateFormat
            {
                get
                { return ((string)(base.GetValue(TimeActivity.DateFormatProperty))); }
                set
                { base.SetValue(TimeActivity.DateFormatProperty, value); }
            }

            /// <summary>
            /// The same of the workflow data dictionary item the calculated time string will be stored in
            /// </summary>
            public static DependencyProperty WorkflowDataProperty = DependencyProperty.Register("WorkflowData", typeof(string), typeof(TimeActivity));
            public string WorkflowData
            {
                get
                { return ((string)(base.GetValue(TimeActivity.WorkflowDataProperty))); }
                set
                { base.SetValue(TimeActivity.WorkflowDataProperty, value); }
            }
            #endregion

            public TimeActivity()
            {
                InitializeComponent();
            }

            private void CalculateDate_ExecuteCode(object sender, EventArgs e)
            {
                DateTimeValue = DateTime.Now.ToString( this.DateFormat );
            }

            private void UpdateWorkflowData_ExecuteCode(object sender, EventArgs e)
            {
                SequentialWorkflow parentWorkflow = null;
                SequentialWorkflow.TryGetContainingWorkflow( this, out parentWorkflow );
                parentWorkflow.WorkflowDictionary.Add( this.WorkflowData , DateTimeValue );
            }

        }
    }


    Frank C. Drewes III - Senior Consultant: Oxford Computer Group

    • Marked as answer by Johan Marais Friday, May 11, 2012 5:18 AM
    Thursday, May 10, 2012 9:14 PM

All replies

  • Johan,

    Regarding the T4FIM FE - - They are going to have to rebuild a new version against the 4.1.xxxx FIM dll's. Not sure when that will happen. Probably once the final build is RTM. I know someone on that team - I'll see if I can get a commitment on that..

    The other way you're trying work it (with the CreatedTime attribute) sounds like a reasonable (and perhaps simpler) way to do it. I'll give it a try in my lab and see what falls out..


    Frank C. Drewes III - Senior Consultant: Oxford Computer Group

    Wednesday, May 9, 2012 4:37 PM
  • Frank,

    Thanks for your help, much appreciated.  In the meantime I am tryiong to write my own Custom workflow to do this in VB and is using the report logging custom workflow as an example, but is having problems with that.  Not much information availbe on how to this from a practical point of view.

    Regards

    Johan


    JkM6228

    Thursday, May 10, 2012 6:05 AM
  • I tried do the same thing you are - and getting the same result.. That really does look like a bug..

    So, the quickest to get this done would be to write your own custom activity. It's a very easy one to do - but there's not much out there that goes through the process of creating a custom activity outside the logging sample. I would probably do this..

    1 - Create a UI that gathers

    • the format you want the date in
    • the workflow parameter to save the result in

    2 - From there, it would be a code activity that gets the current time, converts it to a string in the format passed from the UI and writes it into a workflow data parameter with the name stored in the UI

    The code is simple, but all the other process is where the complexity is. Once you've muddled through it the first time, you'll find it easy to do the next time.

    If I get a chance in the next day or so, I can write it up and share the code on here..


    Frank C. Drewes III - Senior Consultant: Oxford Computer Group

    Thursday, May 10, 2012 7:26 AM
  • Frank,

    Thanks, is relief to know that the use of the CreatedTime / CreatedDate migt be a bug.  Should I post this somewhere for attention? Maybe on Connect?

    Regarding the custom workflow, I agree it sounds pretty straight forward, but from a practical point of view it is not that simple.  I don't have much experience in coding WF activities.  As idicated before, I have used a few examples to write something in VS 2010 which takes a string for the format you want the date in and is suppose to apply this on the date.  Although it compiles without errors and I am also able to do the whole FIM portal configuration without errors, it does not load into the Activity picker.

    Regards

    Johan Marais


    JkM6228

    Thursday, May 10, 2012 9:06 AM
  • Frank,

    I managed to find why the custom workflow is not loading in the activity picker, I didn't specify the Activity Name in the portal properly.  I followed the instructions for the logging example which includes the namesapce as well as the activity name in the proper format.  I used VB which only requires the activity name it seems.

    Now although everything is loaded and appears to be working I am struggling to make the result of the custom function available in the workflow - getting an error in te eventlog which tells me the name I am using is not in the workflow dictionary.

    The struggle continues..:-)

    Regards


    JkM6228

    Thursday, May 10, 2012 11:50 AM
  • I built a quick activity like you were doing.. here's the code for it.. it's not in VB, but you can probably get the idea.

    Have two code activities:

    • CalculateDate
    • UpdateWorkflowData

    executing in that order.

    The UI passes two dependency properties:

    • DateFormat - what format you want the time in (i.e. dd MMM yyyy )
    • WorkflowData - the name of the WF dictionary key I store the result in

    Everything works as expected.. I might have to use this in my next class - quick and easy :)

    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Collections;
    using System.Workflow.ComponentModel;
    using System.Workflow.ComponentModel.Design;
    using System.Workflow.ComponentModel.Compiler;
    using System.Workflow.ComponentModel.Serialization;
    using System.Workflow.Runtime;
    using System.Workflow.Activities;
    using System.Workflow.Activities.Rules;

    // FIM
    using Microsoft.ResourceManagement.Workflow.Activities;

    namespace FIM.CustomActivity
    {
        public partial class TimeActivity : SequenceActivity
        {
            public string DateTimeValue;

            #region Dependency Properties

            /// <summary>
            /// The format used to convert from dateTime to String
            /// </summary>
            public static DependencyProperty DateFormatProperty = DependencyProperty.Register("DateFormat", typeof(string), typeof(TimeActivity));
            public string DateFormat
            {
                get
                { return ((string)(base.GetValue(TimeActivity.DateFormatProperty))); }
                set
                { base.SetValue(TimeActivity.DateFormatProperty, value); }
            }

            /// <summary>
            /// The same of the workflow data dictionary item the calculated time string will be stored in
            /// </summary>
            public static DependencyProperty WorkflowDataProperty = DependencyProperty.Register("WorkflowData", typeof(string), typeof(TimeActivity));
            public string WorkflowData
            {
                get
                { return ((string)(base.GetValue(TimeActivity.WorkflowDataProperty))); }
                set
                { base.SetValue(TimeActivity.WorkflowDataProperty, value); }
            }
            #endregion

            public TimeActivity()
            {
                InitializeComponent();
            }

            private void CalculateDate_ExecuteCode(object sender, EventArgs e)
            {
                DateTimeValue = DateTime.Now.ToString( this.DateFormat );
            }

            private void UpdateWorkflowData_ExecuteCode(object sender, EventArgs e)
            {
                SequentialWorkflow parentWorkflow = null;
                SequentialWorkflow.TryGetContainingWorkflow( this, out parentWorkflow );
                parentWorkflow.WorkflowDictionary.Add( this.WorkflowData , DateTimeValue );
            }

        }
    }


    Frank C. Drewes III - Senior Consultant: Oxford Computer Group

    • Marked as answer by Johan Marais Friday, May 11, 2012 5:18 AM
    Thursday, May 10, 2012 9:14 PM
  • Frank,

    A big thank you, I have implimented the principle above in VB and it works 100%!  An example of the description attribute in AD I wanted to stamp with the date when the object is moved. "Disabled and moved by FIM 2010 on 2012-05-11 07:05:26".  But now this can also be used to move the object into the OU based on the month in which the user exits the company which was another chalenge I had.

    Thanks again for your time and effort.

    Regards

    Johan Marais

    

    JkM6228

    Friday, May 11, 2012 5:17 AM
  • Great - glad it worked the way you needed. Using the different patterns, you can get pretty much any part of the time or date you need.

    Once you've gone through the process of doing a custom activity once or twice it becomes a lot easier, and you can start expanding into new custom activities for other needs. Any non-trivial implementation is going to need some custom code - they just can't put everything 'in-the-box' - although not having time-based or multi-value features in the standard function evaluator is lacking IMO

     


    Frank C. Drewes III - Senior Consultant: Oxford Computer Group

    Friday, May 11, 2012 5:46 AM