Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

opening different form types

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

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

    it worked finally.

    appreciate your help usual Goutam.

    regards.

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

    Hi Ahmad,

    Make sure hsc_originatingleadtype field available in the form.

  • Ahmad Saud Profile Picture
    Ahmad Saud 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,

  • Abed Haniyah Profile Picture
    Abed Haniyah 4,285 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
    Ahmad Saud 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.

  • Verified answer
    gdas Profile Picture
    gdas 50,085 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();
                        }
                    }
    
                }
    
            }
    
        }
    
    }
  • Verified answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans