Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Form Switching in the Unified Interface

(0) ShareShare
ReportReport
Posted on by 10

Hi everyone, I have been given the unenviable task of shifting all our pre-existing Dynamics365 forms and entities over to the new UI.  I have a query.

The previous developer has used a Javascript to change the form that is displayed based on the value in a field, obviously this doesn't work in the UI as the javascript object model has been changed again.  Does anyone have a link they can share to a blog post or documentation that I could use to get this script working under the UI?  (I am not a programmer but I can do basic Javascript customisation for Dynamics).

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: Form Switching in the Unified Interface

    Thanks for the details

    I still don't really see why this isn't working, and I don't find that client-side scripting has changed that much with the Unified Interface.
    On the contrary, I find it even more powerful with more support methods.

    To help you properly troubleshoot this, I advise that you open a Support Request here: https://admin.powerplatform.microsoft.com/support

    Henry

  • UberMunchkin Profile Picture
    UberMunchkin 10 on at
    RE: Form Switching in the Unified Interface

    It just doesn't work, no errors are thrown but changing the value in the field on the form does not trigger the form to change.

    The lblForm variable is set inside a CASE statement:

    switch (relType) {

          case 100000000: //Business Contact

              lblForm = "AI for Sales";

              break;

          case 100000001: //Emergency Contact

              lblForm = "Emergency Contact";

              break;

          case 100000002: //Staff Contact

              lblForm = "Staff Form";

              break;

          case 100000003: //Primary Contact

              lblForm = "Contact";

              break;

    case 100000005: //Enquirer

    lblForm = "Enquirer";

    break;

          default:

              lblForm = "AI for Sales";

      }

    The relType variable that the switch runs on is set to equal the value in the on form optionset field that defines the record type.  

    Thank you for your assistance, I've not got a great deal of experience with Javascript under the new interface and I'm finding it very hard to find solutions for things that used to be very simple under the previous model.

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: Form Switching in the Unified Interface

    As far as I can see, this piece of code should work in the Unified Interface.
    The only point of attention I see is that even though it's still working, Xrm.Page has been deprecated. You should use the formContext instead.

    Can you tell us more about the error message?
    Also the code you shared doesn't tell how you define lblForm, maybe this is something you should investigate.

    Henry

  • UberMunchkin Profile Picture
    UberMunchkin 10 on at
    RE: Form Switching in the Unified Interface

    Hi, thanks for responding.

    I don't see how this is going to work though.  The existing script that I am trying to fix uses the Form Names and a Case Statement, as far as I can tell this is the important part that should be doing the form changing.

    lblForm is equal to the Name of the form set in a CASE statement, based on the value in a 'Customer Type' field.

    I do not have GUIDS for these forms and there are a lot of forms on this entity.

    if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {

          var items = Xrm.Page.ui.formSelector.items.get(); //Get list of available forms from selector.

          for (var i in items) { //Loop through the above list looking for the match.

              var item = items[i];

              var itemId = item.getId();

              var itemLabel = item.getLabel()

              if (itemLabel == lblForm) { //If the label matches then navigate to that form.

                  //navigate to the form

                  item.navigate();

              } //endif

          } //end for

      } //endif

    I don't see a way to convert this to something that will work under the unified interface though.  

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: Form Switching in the Unified Interface

    Hello,

    To help you with UX transition, I also recommend this deck to you: Unified Interface Playbook - Chapter 3: Transition 
    Most developments should keep working in the Unified Interface after the transition if supported methods were used.

    Now in terms of opening a specific form for a record, there are several methods that are available:

    The first one seems more appropriate in your case, as you are already in form context.

    A simple example to navigate to the default "Account" form:

    formContext.ui.formSelector.items.get("8448b78f-8f42-454e-8e2a-f8196b0419af").navigate();

    Henry

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans