locked
How to check if an attribute exists in the entity form CRM 2011 - JavaScript - SDK.MetaData.js RRS feed

  • Question

  • Hi,

    I use the SDK.MetaData.js to retrieve all entities MetaData and attributes MetaData, my issue that i don't know how can i check if an attribute exists in the entity form? (if the attribute is used).

    Could you help me, please?

    Thanks.


    youssef

    Friday, July 20, 2012 9:15 AM

Answers

  • Hi,

    This is the ODATA query for getting the form definition of the main account form:

    ______________________________________________________________________________

    https://<server name>/<org name>/xrmservices/2011/OrganizationData.svc/SystemFormSet?$select=FormXml&$filter=Type/Value eq 2 and Name eq 'Information' and ObjectTypeCode eq 'account'

    ______________________________________________________________________________

    You need to change the value for the ObjectTypeCode. Keep the value in lower case. If you need to read for a custom form or if you changed your default form's name, put that value in the Name filter.

    The output will be the formxml (you might need to encode). Search for the string {datafieldname="<attribute name>"} in this formxml string.

    Search the SDK for more information on making ODATA calls from js. http://msdn.microsoft.com/en-us/library/gg328025.aspx

    Thanks,

    Mayank

    • Marked as answer by essoufy Tuesday, July 24, 2012 7:32 AM
    Monday, July 23, 2012 6:01 PM

All replies

  •  Hi,

    you can check whether the field is present or not in form by the below script

    var ABC= Xrm.Page.getAttribute("your_attribute_name");
        if (ABC != null) {
                    }

    Thanks, 

    Friday, July 20, 2012 9:59 AM
  • thank you for your answer,

    I can not use Xrm.Page, because I will use my code in an entity to collect all the attributes of another entity.

    help, please.


    youssef

    Friday, July 20, 2012 10:54 AM
  • Try reading from the SystemForm entity. Use criteria like objecttypecode, name and type to get the right form, then parse the XML in the FormXml field.

    http://msdn.microsoft.com/en-us/library/gg334669.aspx

    Friday, July 20, 2012 10:12 PM
  • Thanks alot for your reply,
    please, do you have an example to use the entity with javascript

    youssef

    Saturday, July 21, 2012 9:48 AM
  • Hi,

    This is the ODATA query for getting the form definition of the main account form:

    ______________________________________________________________________________

    https://<server name>/<org name>/xrmservices/2011/OrganizationData.svc/SystemFormSet?$select=FormXml&$filter=Type/Value eq 2 and Name eq 'Information' and ObjectTypeCode eq 'account'

    ______________________________________________________________________________

    You need to change the value for the ObjectTypeCode. Keep the value in lower case. If you need to read for a custom form or if you changed your default form's name, put that value in the Name filter.

    The output will be the formxml (you might need to encode). Search for the string {datafieldname="<attribute name>"} in this formxml string.

    Search the SDK for more information on making ODATA calls from js. http://msdn.microsoft.com/en-us/library/gg328025.aspx

    Thanks,

    Mayank

    • Marked as answer by essoufy Tuesday, July 24, 2012 7:32 AM
    Monday, July 23, 2012 6:01 PM