web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Setting datetime returned by custom workflow as output to form field

(0) ShareShare
ReportReport
Posted on by 55,410 Moderator

Hi,

We have a custom workflow activity which returns the datetime output parameter. I have called this custom workflow activity within a workflow and then after getting the output parameter, I am setting the value to the datetime field on an entity form. It works fine if the output parameters returns the datetim value but if there is no value the output parameter is returning the default Datetime.Min value i.e. 1/1/0001 and thus while settng this value on an update entity step, crm fails to update with the error saying "The date/time format is not valid, or the value is outside the supported range."

How do I handle the null check or datetime.minimum check within a workflow or is there any other way to handle this scenario?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi Ravi,

    Did you try to set your own default value :

    [Output("DateTime output")]

    [Default("2004-07-09T02:54:00Z")]

    public InOutArgument<DateTime> DateTime { get; set; }

    you can refer: msdn.microsoft.com/.../gg327984.aspx

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Mahen,

    If I set my own default value hen it will set that value on the field which will not be correct.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Ravi,

    Try setting the default value to date time as follows.

    DateTime? dateSample;
    dateSample.Value = null;
    [Output("DateTime output")]
    [Default(dateSample)]
    public InOutArgument<DateTime> DateTime { get; set; }

    Hope this helps.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Nitya,

    I tried the above above but i don't think it will allow value assignment on the class level. Below is the error am getting-

    2100.err.png

  • Verified answer
    Psyionic Profile Picture
    195 on at

    Hi Ravi,

    The best way to handle this would be using default value Mahender proposed. Then just use validation in workflow itself - add if clause after your custom workflow activity: if your datetime value isn't default - update it on the form, else - do nothing.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at

    Hi Ravi, 

    Try the code below.

    [Output("DateTime output")]
    [Default((DateTime?) null)]
    public InOutArgument<DateTime> DateTime { get; set; }

    Hope this helps.

  • Suggested answer
    Rizwan Aarif Profile Picture
    480 on at

    Hi Ravi,

    You can check the value of output parameter as returned by your custom workflow step for Null using <field contains data> in CRM workflow. To make it work, ensure you have the output paramter as Nullable.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Rizwan,

    We cannot set Nullable type as the output paramter. if we do, we will get the below error on registration-

    ">The type OutArgument`1 of the property <paramtername> is not supported. "

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Nitya,

    We cannot set any type other than string as default. I am getting the below compile error-

    8308.err1.png

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Thanks Oleksandr.

    What I have noticed is that even if you do not set any default value, you will still get the .net default value which is Datetime.Minimum value (1/1/0001). I can check this date within a workflow but was looking for something wherein I don't have to put check within workflow. This is because I have 10 output paramters and out of thos 4 our datetime. After retrieving the parameters I and updating the entity. So if I have to use check within the workflow for the default value then I have to put multiple check/ combination and then have the same update multiple times.

    I have multiple output parameters and in that I have 4 date fields.

    I have seen couple more threads and it seems there is no way we can pass null from within the custom workflow activity. I will have to use those dirty checks witin the workflow :(

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Season of Giving Solutions is Here!

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Shidin Haridas Profile Picture

Shidin Haridas 2

#2
Abdullah13 Profile Picture

Abdullah13 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans