Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Compare Configuration Entity Fields With Contact Entity

(0) ShareShare
ReportReport
Posted on by 89
Hey All,

Hope you all are well, by the way I do have scenario is that I have one custom entity as Configuration which will have some fields like "1)International Customer as Two Option Set, 2)Country as Single Line Of Text, 3)Currency Field, 4)Contact Method as Option Set" and last one special field as "Entity" of Single Line Of Text that can contain Entity's name as Contact or Account. And also all these four fields 1)International Customer, 2)Country, 3)Currency, 4)Contact Method are there in Contact Entity's form with same data type.

What i want to do is that whenever any contact record is created or updated then i want to compare all these fields that are on Contact Record with that Configuration Entity's record fields of wherein Entity field has text as Contact. whether all are exactly same with their data type and their defined data or not.

->If all are true then i need to show into show in Description of contact as Success and all fields are same.
->If any field doesn't have same data or data type then in Description of contact as Failed and which field didn't get matched.

Note: Configuration Entity doesn't have any relationship with any other entities like Contacts, Accounts, etc.
And This needs to be implemented on On-Premise Version not an Online Version.(I have implemented this using Power Automate but as far as i know Power Automate is only for an Online Version).
  • Suggested answer
    Susana Carneiro Profile Picture
    on at
    RE: Compare Configuration Entity Fields With Contact Entity

    Hello Syed,

    To achieve the scenario described you can build a plugin that will be registered on the Post Operation of Create/Update of a Contact.

    Using the plugin context you can get the values of the contact fields using the below as example:

    var new_internationalcustomer_contact = (Boolean)entity.Attributes["new_internationalcustomer"];
    var new_country_contact = entity.Attributes["new_country"].ToString();
    var new_currencyfield_contact = ((Money)entity.Attributes["new_currencyfield"]).Value;
    var new_contactmethod_contact = ((OptionSetValue)entity.Attributes["new_contactmethod"]).Value;

    After that you can use Query Expression to retrieve the configuration records like:

    QueryExpression configurationrecords = new QueryExpression("new_configuration");
    configurationrecords.ColumnSet = new ColumnSet("new_internationalcustomer", "new_country", "new_currencyfield", "new_contactmethod", "new_entity");
    configurationrecords.Criteria.AddCondition("new_entity", ConditionOperator.Equal, "Contact");
    EntityCollection configuration = service.RetrieveMultiple(configurationrecords);

    Then you can get all the details for the mentioned fields like:

    var new_internationalcustomer_config = (Boolean)entity.Attributes["new_internationalcustomer"];
    var new_country_config = config.Attributes["new_country"].ToString();
    var new_currencyfield_config = ((Money)config.Attributes["new_currencyfield"]).Value;
    var new_contactmethod_config = ((OptionSetValue)config.Attributes["new_contactmethod"]).Value;

    After retrieving all this information for each configuration record retrieved you can compared all the fields values using the sample code below:

    if ((new_internationalcustomer_contact == new_internationalcustomer_config) && (new_country_contact == new_country_config) && (new_currencyfield_contact == new_currencyfield_config) && (new_contactmethod_contact == new_contactmethod_config))
         entity.Attributes["description"] = "Success and all fields are same";
    else{
    StringBuilder test = new StringBuilder();
    test.Append("Failed ");

    if (new_internationalcustomer_contact != new_internationalcustomer_config)
    test.Append("new_internationalcustomer ");

    if (new_country_contact != new_country_config)
    test.Append("new_country ");

    if (new_currencyfield_contact != new_currencyfield_config)
    test.Append("new_currencyfield ");

    if (new_contactmethod_contact != new_contactmethod_config)
    test.Append("new_contactmethod ");

    entity.Attributes["description"] = test.ToString();
    }
    service.Update(entity);

    Depending on the context where the plugin is registered you might have to adapt this sample code to your scenario.

    Refer to:

    - itsfascinating.com/.../ - here you will found how to work and get the values for different data type fields.

    - docs.microsoft.com/.../plugin-development - On-premise plug-in development

    - docs.microsoft.com/.../tutorial-write-plug-in - Tutorial: Write and register a plug-in

    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 89

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans