locked
Get CRM form ID RRS feed

  • Question

  • Hi,

       I want to get form ID, there are multiple forms and I want to switch the form based on option set values

    I used this Code it is giving me the Form name but not switching to the form, I am setting the option set value on form load

    after loading it is displaying the Option set value but not switching to the form.

    if(Xrm.Page.getAttribute("dl_recordtype").getValue()==null)
    {
    Xrm.Page.getAttribute("dl_recordtype").setValue(1);
    }
    var form=Xrm.Page.ui.formSelector.getCurrentItem().getLabel().toLowerCase();
    //alert(form);
    if(form != "repair")
    {
    //alert(Xrm.Page.ui.formSelector.getCurrentItem().getLabel().toLowerCase());
        Xrm.Page.ui.formSelector.items.get(1).navigate();
    }

    can anyone help..?

    Thanks

    Wednesday, August 5, 2015 4:52 AM

All replies

  • Hi Yasir,

    Please find below the code,

    First You need to get the form names/Id's statically,  below is the sample with form names,

    function GetFormName(recordType)

    { switch (recordType) { case 100000000: lblForm = "repair"; break; case 100000001: lblForm = "test form1"; break; default: lblForm = "main form"; }

    }

    var lblForm = GetFormName(Xrm.Page.getAttribute("dl_recordtype").getValue())

    if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel().toLowerCase() != 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.toLowerCase() == lblForm) { item.navigate(); } } }



    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

    • Proposed as answer by san Sanz Wednesday, August 5, 2015 7:29 AM
    Wednesday, August 5, 2015 7:29 AM
  • Hi Yasir,

    Try below. Just replace form id with your form id.

    Xrm.Page.ui.formSelector.items.get(formId).navigate()

    Beset option would be to get the form and navigate.

      var form=Xrm.Page.ui.formSelector.getCurrentItem().getLabel().toLowerCase();
                //alert(form);
                if (form != "repair") {
                    var items = Xrm.Page.ui.formSelector.items.get();
                    for (var i in items) {
                        var form = items[i];
                        var formId = form.getId();
                        var formLabel = form.getLabel();
                        if (formLabel == "Information") //Check your condition and accordingly switch to appropriate form
                        {
                            form.navigate();
                        }
                    }
                }

    Thanks!

    Kalim Khan

    Wednesday, August 5, 2015 7:40 AM
  • Hi Kalim,

    Thanks for response, I tried it but it is not switching the existing record to the form which is set in option set value, otherwise is working same like my above code I also want to switch form for existing records base on their option set, you can see above in my code that I am setting the option value on load. and I am switching the form on the base of option set, there is a function on change of the option set after selecting option it will switch to the form which I selected from the drop down but the problem is with existing record I want to open existing record with the form which is selected in option set.

    hope you get my point.

    Thanks


    Wednesday, August 5, 2015 10:04 AM
  • Hi Yasir, can you go through with below code, 

    on Load of your page first call the GetFormId based on optionset,

        function GetFormName(recordType)
    
    { switch (recordType) {
                case 100000000:
                    lblForm = "repair"; //// Replace with form ID
                    break;
                case 100000001:
                    lblForm = "test form1"; //// Replace with form ID
                    break;
                default:
                    lblForm = "main form"; //// Replace with form ID
            }
    
    }
    

    Below code is to navigate to the Form

    var lblForm = GetFormName(Xrm.Page.getAttribute("dl_recordtype").getValue())
    
    if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel().toLowerCase() != 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 (itemId .toLowerCase() == lblForm.toLowerCase() ) {
                        item.navigate();
                    }
                }
            }
    


    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    • Edited by san Sanz Wednesday, August 5, 2015 10:31 AM
    Wednesday, August 5, 2015 10:31 AM
  • hi all, does someone know how to get this working with crm online 2015 update1 the new formhandling of updat1 stopped the working formchanger. did anyone got the formchanger working on the update1? thx, greets peb
    Wednesday, August 5, 2015 10:51 PM