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

Announcements

News and Announcements icon
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

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

    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

    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

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

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 54 Most Valuable Professional

#2
11manish Profile Picture

11manish 21

#3
AT-28040446-0 Profile Picture

AT-28040446-0 13

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans