Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Open form based on associated record in same entity

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi everyone, 

I have 3 main forms in the account entity 

- formA, formB, and formC

When I open some previously created record, it open in the form which was last opened by the user.

I want to open the form in which the record was originally created in. 

Does anyone have code for the same requirement? 

Thanks 

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    Figured it out.. Here is the correct function. There was a parenthesis problem that was causing the issue. Thanks to everyone who helped me!

    function onLoad()

    {

    //if the form is update form

    if (Xrm.Page.ui.getFormType()==2){

      // variable to store the name of the form

      var lblForm;

      // get the value picklist field

      var relType = Xrm.Page.getAttribute("new_formname").getValue();

      // switch statement to assign the form to the picklist value

      //change the switch statement based on the forms numbers and picklist values

      switch (relType) {

      case 'AccountC':

      lblForm = "AccountC";

      break;

      case 'AccountB':

      lblForm = "AccountB";

      break;

      default:

      lblForm = "AccountA";

      }

      //check if the current form is form need to be displayed based on the value

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

      var items = Xrm.Page.ui.formSelector.items.get();

      for (var i in items) {

      var item = items[i];

      var itemId = item.getId();

      var itemLabel = item.getLabel()

      if (itemLabel == lblForm) {

      //navigate to the form

      item.navigate();

      return;

      } //endif

      } //end for

      } //endif

    }

    }//endif

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    I am still experiencing a few issues.

    1) When I create a new record and click on "save and close" or "save" it saves and automatically opens a new AccountA form. When I try to switch to AccountB or Account C form from the dropdown, it gives this the following pop up and again opens AccountA form.

    Screen-Shot-2017_2D00_11_2D00_28-at-1.23.30-PM.jpg

    Any changes to be made to the code?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    It works like a charm! Thank you so much!!

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Open form based on associated record in same entity

    Hello,

    There is issue in your code, use following code, it's working fine for me

    function onLoad()
    {
    
    //if the form is update form
    if (Xrm.Page.ui.getFormType()==2)
       // variable to store the name of the form
       var lblForm;
       // get the value picklist field
       var relType = Xrm.Page.getAttribute("new_formname").getValue();
       // switch statement to assign the form to the picklist value
       //change the switch statement based on the forms numbers and picklist values
       switch (relType) {
           case 'AccountC':
               lblForm = "AccountC";
               break;
           case 'AccountB':
               lblForm = "AccountB";
               break;
           default:
               lblForm = "AccountA";
       }
       //check if the current form is form need to be displayed based on the value
       if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() != lblForm) {
           var items = Xrm.Page.ui.formSelector.items.get();
           for (var i in items) {
               var item = items[i];
               var itemId = item.getId();
               var itemLabel = item.getLabel()
               if (itemLabel == lblForm) {
                   //navigate to the form
                   item.navigate();
    			   return;
               } //endif
           } //end for
       } //endif
    }//endif
    
    


  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    @oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx line 159 > eval:1:1
    RunHandlerInternal@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
    RunHandlers@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
    OnScriptTagLoaded@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx
    AppendScriptTag/scriptTag.onload/<@oticon.crm8.dynamics.com/.../ClientApiWrapper.aspx

    This is the log file. Thank you. 

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Open form based on associated record in same entity

    Hello,

    Can you download and share log file here,  in what line you are getting this error ??

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    Hello, 

    I used the alert(relType) and it returned the form name from custom field on the pop up. I am getting the following page script error.

     8244.Screen-Shot-2017_2D00_11_2D00_27-at-10.15.23-PM.png

    I am unable to debug the error. Please offer a solution. 

    Thanks. 

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Open form based on associated record in same entity

    Hello,

    First make sure this field have value or not, you can simply put a alert on that, alert(relType ), you can also debug your script just using debugger keyword, are you getting any error ?? any page script error ??

    Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    I have applied the following code for my custom field "new_formname" but it isnt working. It is a single line of text field and not a picklist field (does that make a difference - any changes in code necessary?).

    Please help. Thanks.

    //if the form is update form

    if (Xrm.Page.ui.getFormType()==2)

       // variable to store the name of the form

       var lblForm;

       // get the value picklist field

       var relType = Xrm.Page.getAttribute("new_formname").getValue();

       // switch statement to assign the form to the picklist value

       //change the switch statement based on the forms numbers and picklist values

       switch (relType) {

           case 1:

               lblForm = "AccountC";

               break;

           case 2:

               lblForm = "AccountB";

               break;

           default:

               lblForm = "AccountA";

       }

       //check if the current form is form need to be displayed based on the value

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

           var items = Xrm.Page.ui.formSelector.items.get();

           for (var i in items) {

               var item = items[i];

               var itemId = item.getId();

               var itemLabel = item.getLabel()

               if (itemLabel == lblForm) {

                   //navigate to the form

                   item.navigate();

               } //endif

           } //end for

       } //endif

    }//endif

    } //end function

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Open form based on associated record in same entity

    I have applied function on my forms to save the form name on a custom field.

    Now, how can I open the corresponding form? Can you please share the code for the same. Thanks in advance.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans