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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

opening different form types

(0) ShareShare
ReportReport
Posted on by 790

Dear all

 

I do have two form types of OPPORTUNITY, as below , these are two different forms with different fields, now , ONE agent can create opportunities of different types (different forms), my issue is that when opening an existing opportunity, system does not open the right form for that opportunity, instead, it opens that last opened form.

So , how to configure system to open the right form type that belongs to a particular opportunity record.

 2018_2D00_10_2D00_12-22_5F00_56_5F00_20_2D00_opening-different-form-types-_2D00_-Message-_2800_HTML_2900_.png

Thanks,

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at
    RE: opening different form types

    Hi Ahmad,

    You can do this using form selector.

    here are some information

    community.dynamics.com/.../226961

    community.dynamics.com/.../180615

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: opening different form types

    Hi Ahmad,

    Ideally out of the box its not possible because dynamics CRM records does not associate with the form id so CRM does not know which form you basically create the record .

    So it will be better that keep a flag (Or any existing field by which you identify the record to open which form) to identify when and which forms the record is created and based on the flag value redirect the particular form in the update mode. Here is the sample code to do that , Make sure you register below method in both the form on load ,  just change the form names and the flag field name .

    Hope this helps 

    function OnLoadFormSelector() {
        if (Xrm.Page.ui.getFormType() == 2) { // This will trigger only when Update form
            var lblForm;
            var marketType = Xrm.Page.getAttribute("new_markettype").getValue(); //Get the optionset value , replace the optionset field name
            switch (marketType) {
                case 100001:   // Replace the optionset value
                    lblForm = "Opportunity Form 1";  // Replace Form name based on optionset value
                    break;
                case 100003:
                    lblForm = "Opportunity Form 2";
                    break;
                default:
                    lblForm = "Opportunity Form 1";
            }
            var formLabel = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();
            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) {
                        if (itemLabel != formLabel) {                       
                            item.navigate();
                        }
                    }
    
                }
    
            }
    
        }
    
    }
  • Ahmad Saud Profile Picture
    790 on at
    RE: opening different form types

    thanks, but i am facing an error when opening an existing opportunity.

    the code  is :

    function OnLoadFormSelector() {

       if (Xrm.Page.ui.getFormType() == 2) { // This will trigger only when Update form

           var lblForm;

           //THIS LINE IS GENERATING THE ERROR

           var OPP_Type = Xrm.Page.getAttribute("hsc_originatingleadtype").getValue(); //Get the optionset value , replace the optionset field name

           switch (OPP_Type) {

               case "Restaurant Lead":   // Replace the optionset value

                   lblForm = "Opportunity-form-1";  // Replace Form name based on optionset value

                   break;

               case "Marketing Lead":

                   lblForm = "Opportunity-form-2";

                   break;

               default:

                   lblForm = "Opportunity";

           }

           var formLabel = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

           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) {

                       if (itemLabel != formLabel) {

                           item.navigate();

                       }

                   }

               }

           }

       }

    }

    and the error Is :

    TypeError: Cannot read property 'getValue' of null

       at OnLoadFormSelector (hungerstation-sb.crm4.dynamics.com/.../hsc_opportunity_form_selector_based_on_lead_type)

    thanks.

  • Abed Haniyah Profile Picture
    4,287 on at
    RE: opening different form types

    Hello Ahamad,

    Xrm.Page.getAttribute("hsc_originatingleadtype").getValue();  it will retrieve the option set value (number), you can use Xrm.Page.getAttribute("hsc_originatingleadtype").getText(); for retrieving the option set label (text).

    Also try to debug your code by using the the browser : developers.google.com/.../javascript

    Hope this help.

  • Ahmad Saud Profile Picture
    790 on at
    RE: opening different form types

    thanks you Abed

    but the i got the same error.

    note: the field type is text-calculated field. i tried both getText and getValue and both gave me the same error.

    thanks,

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: opening different form types

    Hi Ahmad,

    Make sure hsc_originatingleadtype field available in the form.

  • Ahmad Saud Profile Picture
    790 on at
    RE: opening different form types

    it worked finally.

    appreciate your help usual Goutam.

    regards.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans