web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Open form based on associated record in same entity

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    This is a default behaviour of CRM, you can write a small code on OnSave event of form to capture form name in some custom text field. Further you can use script to read this field and load specifc form using Script check this: www.magnetismsolutions.com/.../how-to-switch-a-dynamics-crm-form-based-on-a-value

    Or you can have server side code for this

    gonzaloruizcrm.blogspot.in/.../avoiding-form-reload-when-switching-crm.html

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    it will be tricky but what you could do is as follow:

    1 when record is created save the form name in a field

    2 when you load check the value in this field

    3 if the name is the same as the current it is fine

    else use javascript to redirect you to the correct form

    here are sample of Jscript code: community.dynamics.com/.../223710

  • Community Member Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

    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

  • Mahendar Pal Profile Picture
    45,095 on at

    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
    on at

    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
    45,095 on at

    Hello,

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

  • Community Member Profile Picture
    on at

    @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
    45,095 on at

    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
    on at

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

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans