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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

  • Community Member Profile Picture
    on at

    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
    50,091 Moderator on at

    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");
                                }
                            }


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

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
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans