Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Retrieve DateTime field and set it on another entity's DateTime field in Dynamics CRM Plugin

Posted on by Microsoft Employee

Hi,

I have a requirement of creating a custom entity on create of an entity, say incident and copy this entity's data to the custom entity.

There are some date time fields which I need to copy the data to the custom entity.

I don't know the syntax for the same, I am doing this through a plugin, On post create.

Kindly suggest.

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Retrieve DateTime field and set it on another entity's DateTime field in Dynamics CRM Plugin

    Yes you can , just replace postimage entity with getting entity from context -

                            //Declare Datetime Variable
                            DateTime? dateTimeVar = null;
                            //Retrieve entity from context
                            Entity _entity = (Entity)_context.InputParameters["Target"];
                        
                            if (_entity.Attributes.Contains("DateTimeFieldName"))
                            {
                                if (Convert.ToString(_entity.GetAttributeValue<DateTime?>("DateTimeFieldName")) != "" && (_entity.GetAttributeValue<DateTime?>("DateTimeFieldName")) != null)
                                {
                                    dateTimeVar = _entity.GetAttributeValue<DateTime?>("DateTimeFieldName");
                                }
                            }


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Retrieve DateTime field and set it on another entity's DateTime field in Dynamics CRM Plugin

    Hi Goutam,

    I am not using Post Image currently for this plugin. Can I achieve this by retreieving from context?

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Retrieve DateTime field and set it on another entity's DateTime field in Dynamics CRM Plugin

    Hi ,

    Try with this -

                            //Declare Datetime Variable
                            DateTime? dateTimeVar = null;
                            //Retrieve Post Images ,  get the postImage from context
                            Entity postImage = (context.PostEntityImages != null && context.PostEntityImages.Contains("PostImage")) ? context.PostEntityImages["PostImage"] : null;
                            //Retrieve date from PostImages, Replace DateTimeFieldName
                            if (postImage.Attributes.Contains("DateTimeFieldName"))
                            {
                                if (Convert.ToString(postImage.GetAttributeValue<DateTime?>("DateTimeFieldName")) != "" && (postImage.GetAttributeValue<DateTime?>("DateTimeFieldName")) != null)
                                {
                                    dateTimeVar = postImage.GetAttributeValue<DateTime?>("DateTimeFieldName");
                                }
                            }



    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans