Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Compare Configuration Entity Fields With Contact Entity

Posted on by 85
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
    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans