locked
CRM2011: How to get object type code by entity name RRS feed

  • Question

  • I want to get the object type code by passing the entity name, how to do in JavaScript?
    Tuesday, February 21, 2012 6:37 AM

Answers

  • I find out the way:

    function GetObjectTypeCode(entityName) {


        try {

            var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
            lookupService.SetParameter("entityName", entityName);
            var result = lookupService.Execute();

            if (result.Success && typeof result.ReturnValue == "number") {
                return result.ReturnValue;
            } else {
                return null;
            }
        }
        catch (ex) {
            throw ex;
        }
    }
    • Marked as answer by nixjojo Tuesday, February 21, 2012 7:27 AM
    Tuesday, February 21, 2012 7:27 AM

All replies

  •       Hi,

          "ObjectTypeCode” resides in “etc” query string  parameter. Then you could use the below JScript statement to get “ObjectTypeCode”

      var currEntityObjTypeCode= Xrm.Page.context.getQueryStringParameters().etc

      I hope it helps !

      Kelly


    Please visit my blog about CRM and other technical things: http://kellyhoang.blogspot.com/

    • Proposed as answer by Kelly Hoang Tuesday, February 21, 2012 6:48 AM
    Tuesday, February 21, 2012 6:47 AM
  • Thanks Kelly,

    I know there some methods to get the object type code, do you know how to get OTC by entity name?

    Tuesday, February 21, 2012 6:53 AM
  • I find out the way:

    function GetObjectTypeCode(entityName) {


        try {

            var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
            lookupService.SetParameter("entityName", entityName);
            var result = lookupService.Execute();

            if (result.Success && typeof result.ReturnValue == "number") {
                return result.ReturnValue;
            } else {
                return null;
            }
        }
        catch (ex) {
            throw ex;
        }
    }
    • Marked as answer by nixjojo Tuesday, February 21, 2012 7:27 AM
    Tuesday, February 21, 2012 7:27 AM
  • Hi,

        You can get object type code by fallowing java script code.

        var objTypeCode = crmForm.ObjectTypeCode; //works till roll-up 11

        var objTypeCode = Xrm.Page.context.getQueryStringParameters().etc; //works in roll-up 12/13

    for other java script issues due to roll-up 12 please open this url

    http://crmjavascripts.blogspot.in/2013/05/crm-java-scripts-for-rollup-12-changes.html

    Thanks !!







    • Proposed as answer by Neo Yadav Thursday, May 30, 2013 7:06 AM
    • Edited by Neo Yadav Tuesday, June 18, 2013 11:51 AM
    Thursday, May 30, 2013 7:06 AM