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

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

Pass field value from different entity using plugin

(0) ShareShare
ReportReport
Posted on by 760

Hi,

I'm new to plugins and I'm trying to understand it. I just wanted to be able to assign a filed value based on a value from the other entity. I have this simple code but now working.

I wanted to pass the description value from account to the field named new_summary in my entity called new_grade

Entity g = new Entity("new_grade");

Entity a = new Entity("account");

string getSummary = a.GetAttributeValue<string>("description");

 g["new_summary"] = getSummary;

Entity entityImage = localContext.PostImage;

g["new_account] = entityImage.ToEntityReference();

localContext.OrganizationService.Create(g);

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Pass field value from different entity using plugin

    Hello,

    Can you please describe scenario of your plugin a bit wider? Like "When user creates Grade record that is child for Account (field new_account) - description field from account has to be copied to new_summary field".

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Pass field value from different entity using plugin

    Hi,

    You plugin steps are registered on Post Operation execution pipeling.

    replace below lin of code

    Entity entityImage = localContext.PostImage;

    g["new_account] = entityImage.ToEntityReference();

    with

    Entity entityImage = localContext.PostImage;

    g["new_account] = new EntityReference("account",entityImage .Id);

    You could direcly use below code to set lookup field on new_grade

    g["new_account] = new EntityReference("account",a.Id); //WHERE  a IS ACCOUNT ENTITY CONTEXT

    Make sure you have have registered Post Image for the steps.

    Please mark my answer verified if i were helpful

  • CRMexplorer Profile Picture
    760 on at
    RE: Pass field value from different entity using plugin

    your understanding is correct, that's the exact scenario When user creates Grade record that is child for Account (field new_account) - description field from account has to be copied to new_summary field".

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Pass field value from different entity using plugin

    Then you should try following code:

    var target = localContext.PluginExecutionContext.InputParameters["Target"] as Entity;
    
    var accountRef = target.GetAttributeValue("new_account");
    
    if (accountRef == null){
    	return;
    }
    
    var account = localContext.OrganizationService.Retrieve("account", accountRef.Id, new ColumnSet("description"));
    
    target["new_summary"] = account.GetAttributeValue("description");

    Also your plugin should be registered to work in Pre-Operation mode.

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at
    RE: Pass field value from different entity using plugin

    HI,

    You can achieve your requirement without writting code as well.

    Navigate to Settings->Customization->Customize the system->Entity->Account->Relationship(1:N)->Open Related entity Grade relationship ->Add new mapping->Select source and target field

    CQ10.PNG

    Note:- 

    1. Data Type should be Same in Account and Grade entity for description field

    2. Field Length should be greated than in Grade from Account

    a33ik Please correct me If I am wrong.

    Please mark my answer verified if i were helpful

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 36 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans