Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Cant get a field to populate on record creation

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi Everybody,

What i want to do is update a fields value with another value , which is entered on creation of the record.

Im getting no errors which is annoying but im also thinking that i cant get the value of the field im trying to copy because it has not been saved to the database.

Any Ideas?

switch (context.MessageName)
{
case "Create":
{
switch (context.Stage)
{
case 20: // Pre-Operation
{


if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity createEntity = (Entity)context.InputParameters["Target"];

//Entity postMeImage = (Entity)context.PostEntityImages["postImage"];

string postGroup = string.Empty;
postGroup = ((EntityReference)createEntity.Attributes["codec_primaryprofessionalgroup"]).Name;
createEntity["codec_professionalgroups"] = postGroup;

*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Cant get a field to populate on record creation

    Hi,

    Can you share your complete code please and details of the field you are updating/ copying?

    Also, this requirement can be done by real time workflow as well. So if you do not have any specific requirement to use plugins, I would suggest to use real time workflow to copy field value.

    Hope this helps.

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 1,014 Super User 2024 Season 2 on at
    RE: Cant get a field to populate on record creation

    Hi Jonathan85720535,

    One approach is to create a function for checking the message name of the context passed into it.

    private bool IsCreateMessage(IPluginExecutionContext context)
    {
        return context.MessageName.Equals("create", StringComparison.OrdinalIgnoreCase);
    }

    Lookup fields in Dynamics 365 need to be set the EntityReference. This means that you need to know the LogicalName of the entity the lookup is pointing to and the ID of the target record. For example.

    Entity recordToUpdate = service.Retrieve("currentEntity", currentEntityId, new ColumnSet(true));
    recordToUpdate["lookupid"] = new EntityReference("destinationEntity", destinationRecordId);
    service.Update(recordToUpdate);

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans