locked
CRM 2011: Get form name using javascript RRS feed

  • Question

  • Hi all, Is there anyway to get the form name using java script ?

    I have an entity with two forms, I need execute some code in one of them only, not in both forms.

    Anyway to do it ??

    Thanks and best regards..

    Sunday, July 8, 2012 5:43 PM

Answers

All replies

  • Sunday, July 8, 2012 7:47 PM
  • not working, object is null or undefined
    Monday, July 9, 2012 7:49 AM
  • If your entity has only one form defined, .getCurrentItem() will return null; in which case you can reference the first (and only) form directly:

    var formLabel = Xrm.Page.ui.formSelector.items.get(0).getLabel();


    --pogo (pat) @ pogo69.wordpress.com

    Monday, July 9, 2012 10:55 AM
  • I have multiple forms, but the above error ocurred
    Monday, July 9, 2012 11:31 AM
  • Hi, try this,

    var forms = Xrm.Page.ui.formSelector.items.get();
        var i = 0;
        for (i = 0; i < forms.length; i++) {
            if (forms[i].getLabel().toLowerCase() == 'small case form name') {
               //your logic here
    		}
    	}


    NarSr If you find this answer as help ful please vote as helpful and if you find this as answer Please Mark It as Answer :)

    Monday, July 9, 2012 12:43 PM

  • var forms = Xrm.Page.ui.formSelector.items.get();
        var i = 0;
        for (i = 0; i < forms.length; i++) {
            if (forms[i].getLabel().toLowerCase() == 'small case form name') {
               //your logic here
    		}
    	}

    I tried the following:

    var forms = Xrm.Page.ui.formSelector.items.get();
    alert(forms.length)

    And it displays 0 although I have two forms, does it depends on the current user or its security role, i.e: If the current security role is selected only in one form, is it counted by the system as only one form ??

    Best regards..

    Monday, July 9, 2012 12:51 PM
  • Hi Mostafa,

    Yes it is. Following is from the documentation.

    Only those forms that share an association with one of the user’s security roles
    are available in this collection. This collection provides methods to retrieve
    or perform actions on each of the forms, including the ability to navigate to a
    specific form.

    Hope it helps...!! :)


    Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"

    Monday, July 9, 2012 12:59 PM
  • Yes. Just add the surty role (that user is having) to the two forms.


    NarSr If you find this answer as help ful please vote as helpful and if you find this as answer Please Mark It as Answer :)

    Tuesday, July 10, 2012 6:01 AM
  • Hi

    Just a note to other readers the code "var formLabel = Xrm.Page.ui.formSelector.items.get(0).getLabel" does not work. As noted in the SDK if only one form is available to the user/entity combination "Xrm.Page.ui.formSelector" return is empty, there is no [0] item to get.

    Paul

    Monday, September 17, 2012 6:09 PM
  • All of the above mentioned solutions will only work if two things are true.

    1. There is more than one form associated with any of the current users security roles, AND
    2. The Navigation bar is displayed on the current form.  If the Navigation side panel is hidden then all of the above options will return null or empty.  

    If the above two statements are true then the following will get you the current form name (getId() returns the current form Id).

    Xrm.Page.ui.formSelector.getCurrentItem().getLabel()

    Xrm.Page.ui.formSelector.items.get().getLabel()

    I haven't found a way around this except to write a function that makes an OData call to the SystemFormSet.  But you have to know the id of the form already.

    oDataEndpointUrl += "SystemFormSet?$top=1&$filter=ObjectTypeCode eq '" + formEntity + "' and Name eq '" + formName + "'";


    Louis





    • Edited by CMerc Thursday, May 16, 2013 5:18 PM
    • Proposed as answer by CMerc Thursday, May 16, 2013 5:18 PM
    Thursday, May 16, 2013 5:11 PM
  • Hi ,

    is there any way to get name of the form when its only one. I don't want give access to other form .

     I want to work it in case of only one!

    thanks 



    Pooja

    Monday, October 28, 2013 10:11 AM
  • Just create your own variable called FormName.   Call a function in your Onload function that sets the var value.   In each form set the var to a constant equal to the form's name.
    Wednesday, November 26, 2014 12:23 AM