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.

      42 comments:

      1. Replies
        1. IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Projects for CSE It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

          JavaScript Online Training in India

          JavaScript Training in India

          The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

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

        ReplyDelete
      3. An astounding web diary I visit this blog, it's inconceivably magnificent. Strangely, in this current blog's substance made point of fact and sensible. The substance of information is instructive.
        Oracle Fusion Financials Online Training
        Oracle Fusion HCM Online Training
        Oracle Fusion SCM Online Training

        ReplyDelete
      4. 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
      5. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        workday studio online training
        best workday studio online training
        top workday studio online training

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

        ReplyDelete
      7. 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
      8. Thanks for sharing, great post!

        Áo khoác Đà Lạt chuyên sỉ và lẻ áo khoác áo khoác nam với giá ưu đãi nhất 2020. Luôn cập nhật mẫu mới chất lượng và dày ấm nhất kể cả với thời tiết lạnh giá các nước có du học sinh và xuất khẩu lao động. Aokhoacdalat.com được đồng hành cùng các bạn!!!!

        ReplyDelete
      9. Thanks for sharing this information. I really Like Very Much.
        angular js online training

        ReplyDelete
      10. Thanks for sharing this information. I really Like Very Much.
        angular js online training

        ReplyDelete
      11. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        angular js online training
        best angular js online training
        top angular js online training

        ReplyDelete
      12. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        angular js online training
        best angular js online training
        top angular js online training

        ReplyDelete
      13. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        devops online training
        best devops online training
        top devops online training

        ReplyDelete
      14. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        angular js online training
        best angular js online training
        top angular js online training

        ReplyDelete
      15. houses for sale in bangalore
        Chartered Housing is one of the best Real estate developers in Bangalore, and we undertake a variety of real estate projects such as apartments, villas, plots, etc. • Chartered Housing is one of the best real estate developers in Bangalore, and we undertake a variety of real estate projects such as apartments, villas, plots etc.

        ReplyDelete
      16. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        blockchain online training

        ReplyDelete
      17. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
        angular js online training
        best angular js online training
        top angular js online training

        ReplyDelete
      18. Thanks for sharing great informational content.
        Read latest technology related blogs
        grabify
        dns probe finished no internet

        ReplyDelete
      19. 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
      20. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website Workday HCM Online Training
        best Workday HCM Online Training
        top Workday HCM Online Training

        ReplyDelete
      21. 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
      22. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website mulesoft online training
        best mulesoft online training
        top mulesoft online training

        ReplyDelete
      23. 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
      24. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website Workday HCM Online Training
        best Workday HCM Online Training
        top Workday HCM Online Training

        ReplyDelete
      25. Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website Workday HCM Online Training
        best Workday HCM Online Training
        top Workday HCM Online Training

        ReplyDelete