Skip to main content

Notifications

Announcements

No record found.

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

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Setting datetime returned by custom workflow as output to form field

    Thanks Andrew for you response. I was trying to avoid checking the datetime value before the update entity step cause in this case I will need to add multiple if check combinations i.e. if date1 = null & (date2 != null && date3 != null && date4 != null) .. if date2 = null & (date1 != null && date3 != null && date4 != null) and so on.

    I achieved this in the similar fashion but by setting the CRM minimum datetime for the null date paramters. This way I do not need to put check before updating the entity i.e. I am updating the entity with the value returned by the parameter. And then add check if the date paramters is null.. if yes then clear that date field.

    The above help in in future maintenance as I now just have to change one update entity step if required.

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Setting datetime returned by custom workflow as output to form field

    Ravi,

    I would recommend to add another one boolean output to your custom workflow activity. I believe you can detect inside your code was DateTime output set or no so populate that boolean output with false if it was not set and with true if it was and use that output together with your DateTime output - update field if boolean output is true (so DateTime output has valid datetime) and don't update it in opposite case.

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Setting datetime returned by custom workflow as output to form field

    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 :(

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Setting datetime returned by custom workflow as output to form field

    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
    RE: Setting datetime returned by custom workflow as output to form field

    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. "

  • Suggested answer
    Rizwan Aarif Profile Picture
    480 on at
    RE: Setting datetime returned by custom workflow as output to form field

    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.

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Setting datetime returned by custom workflow as output to form field

    Hi Ravi, 

    Try the code below.

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

    Hope this helps.

  • Verified answer
    Psyionic Profile Picture
    195 on at
    RE: Setting datetime returned by custom workflow as output to form field

    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.

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Setting datetime returned by custom workflow as output to form field

    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

  • Suggested answer
    Nithya Gopinath Profile Picture
    17,078 on at
    RE: Setting datetime returned by custom workflow as output to form field

    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.

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

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans