Sunday, October 15, 2017

PowerApps and CRM optionsets

In this blog, I will walk you through the steps on how to work with the Dynamics CRM option sets in PowerApps. I will be extending the app I built in my last blog CRM and PowerApps revisited.

Problem Statement

The problem is that if you use out of the box Dynamics 365 Connector for PowerApps, it only retrieves the numeric value of the optionset. It does not return the text value of the optionsets. Below, I have added a Preferred Method of Contact field to the DetailScreen1.
2017-10-14_22-57-42
As shown in the screenshot above, Preferred Method of Contact of 1 means nothing to a business user. It should display email, phone, mail, etc.

Solution

The Dynamics CRM connector for PowerApps does not display the text values of the optionsets or the metadata of the entities. So, there is no straight forward solution for this problem, but we can use something similar to a data maps table that contains what these numeric values mean.

Here are the steps:

Create a collection

We will create a collection (https://powerapps.microsoft.com/en-us/tutorials/create-update-collection/) to store the optionset values and the corresponding text.
1. Open the BrowseScreen1, choose On Start from the Actions Menu and add the following code.
Collect(Myc, {optionset:"PreferedContact", OptionValue:1,DisplayText:"Any"},{optionset:"PreferedContact", OptionValue:2,DisplayText:"Email"},{optionset:"PreferedContact", OptionValue:3,DisplayText:"Phone"},{optionset:"PreferedContact", OptionValue:3,DisplayText:"Fax"},{optionset:"PreferedContact", OptionValue:3,DisplayText:"Mail"})
2017-10-14_23-23-02
The above code will create a collection Myc.
  • DisplayText- displays the text of the optionset
  • OptionValue- displays the numeric value of the optionset
  • Optionset- displays the name of the optionset field. This field will be useful to the store the values for the multiple optionset fields in the same collection.

    2017-10-14_23-37-28

    Display the Optionset Text

    We will be using the PowerApps Lookup function to display the text for the optionset.
    1. Open the DetailScreen1 and select the optionset field, as shown on the screen in the screenshot below.

      2017-10-14_23-57-52
    2. Click on the Unlock the change properties.
    3. Change the Data property to LookUp(Myc,((OptionValue=preferredcontactmethodcode)&&(optionset="PreferedContact")),DisplayText).
    4. The DetailScreen1 will display the text associated with the optionset numeric value.

      2017-10-15_21-56-13

      Editing the Optionsets in PowerApps

      The above solution can show the text, but won’t let the user edit the values in the app. The solution to allow users to edit the optionsets values in PowerApps is little tricky.
      Here are the steps to achieve this.
      1. Add the Preferred Method of Contact optionset to EditScreen1.
      2. Change the display for the field to Allowed Values as shown in the screenshot below. It will change the field to a dropdown field.

        2017-10-15_22-12-51
      3. Click on the Unlock the change properties.
      4. Select the dropdown field and change the Items property to collection Myc. In the dropdown properties pane, select the column to display in the Value field. By default, the first column of the collection is selected.

        2017-10-15_22-30-50
      5. Change the Default property to LookUp(Myc,((OptionValue=preferredcontactmethodcode)&&(optionset="PreferedContact")),DisplayText).
      6. Select the optionset card and change the Update property to DataCardValue4.Selected.OptionValue. This will tell the card to use the OptionValue field of the collection to update in CRM.

        2017-10-15_22-46-06
      7. Save the application and test it.
      I hope this helps.

      18 comments:

      1. All given information was wonderful and thanks for sharing.
        Microsoft Dynamics AX Online Training

        ReplyDelete
      2. Thank your valuable Information...
        Yaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
        Best video editing services in Hyderabad,ameerpet
        Best Graphic Designing services in Hyderabad,ameerpet­
        Best Ad Making services in Hyderabad,ameerpet­

        ReplyDelete
      3. This comment has been removed by the author.

        ReplyDelete
      4. Thanks for sharing, nice post! Post really provice useful information!

        Hương Lâm chuyên cung cấp máy photocopy, chúng tôi cung cấp máy photocopy ricoh, toshiba, canon, sharp, đặc biệt chúng tôi có cung cấp máy photocopy màu uy tín, giá rẻ nhất.

        ReplyDelete
      5. Are you in need of a Loan/Funding for a project? Have you been trying to obtain a Loan from any of the Banks or Loan Companies and got Ripped off and they have refused to grant you the Loan because of bad credit? we offer all types of non-recourse Loan and funding at a low Interest Rate of 3% both long term and short term.

        The categories of Loan/financial funding offered include but not limited to: Business Loan, Personal Loan, Company Loan, Mortgage Loan, debt consolidation and financial funding for both turnkey and mega projects E.T.C. from a minimum of Euro / US$1Million to Euro / US$5Billion Max.

        Kindly get in touch for further details and procedure markthomasfinanceltd@gmail.com
        Whats-App no +919667837169
        Dr. Mark Thomas
        Regards

        ReplyDelete
      6. Do you need personal loan?
        Loan for your home improvements,
        Mortgage loan,
        Debt consolidation loan,
        Commercial loan,
        Education loan,
        Car loan,
        Loan for assets.
        financialserviceoffer876@gmail.com WhatsApp +918929509036

        ReplyDelete
      7. Emergency Cash Loans Hello Everybody, My name is Mrs. Phyllis Sue South. I live in UK London and i am a happy woman today? and i told my self that any lender that rescue my family from our poor situation, i will refer any person that is looking for loan to him, he gave me happiness to me and my family, i was in need of a loan of $350,000.00 to start my life all over as i am a single mother with 2 kids I met this honest and GOD fearing man loan lender that help me with a loan of $350,000.00 U.S. Dollar, he is a GOD fearing man, if you are in need of loan and you will pay back the loan please contact him tell him that is Mrs. Phyllis Sue South that refer you to him. contact Dr. James Eric via email: financialserviceoffer876@gmail.com Whats-App +918929509036

        ReplyDelete
      8. Thank you for sharing this informative and engaging blog post. I found the content to be both interesting and thought-provoking. Your writing style is clear and concise, making it easy to follow along and understand the key points.

        Dynamics Experts Dubai

        ReplyDelete
      9. Thank you for sharing this informative and engaging blog post. I found the content to be both interesting and thought-provoking. Your writing style is clear and concise, making it easy to follow along and understand the key points.

        Microsoft Dynamics Experts

        ReplyDelete