Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Multiple forms in single entity

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have 3 forms in the accounts entity. AccountA (default out of the box form), AccountB, AccountC

I have created a custom field (type: single line of text) to store the value of the form the record was created in. 

I used the following javascript to open the correct form based on the field value. Although the correct form is opening onLoad, I'm now experiencing other issues: 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_2D00_640x480.jpg

Here is the code I used: 

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


Please help me solve this problem. Thank you!  



*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Multiple forms in single entity

    It worked thanks so much! Can't believe it was such a small mistake.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Multiple forms in single entity

    Hi,

    I think you have a bracket problem.

    Could you please try this:

    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: Multiple forms in single entity

    changing it to getText() throws a script error onload of form

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Multiple forms in single entity

    If new_formname field is option set then your code wont work. getValue will give you optionset value not the label. to get label use this line

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

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans