Advertisements

Archive

Posts Tagged ‘Java script’

Reading Querystring using Jscript

January 24, 2012 1 comment

Hi,

Below is the Jscript function to parse query string (i.e., In to Parameter & Value pair)

// Read querystring and returns Parameter & Value pair Array

function fetchQueryStringParams() {

var qrStr = window.location.search;

var spQrStr = qrStr.substring(1);

var arrQrStr = new Array();

// splits each of pair

var arr = spQrStr.split(‘&’);

for (var i = 0; i < arr.length; i++) {

// splits each of field-value pair

var index = arr[i].indexOf(‘=’);

var key = arr[i].substring(0, index);

var val = arr[i].substring(index + 1);

// saves each of field-value pair in an array variable

arrQrStr[key] = val;

}

return arrQrStr;

}

How do I call this method?

function onload() {

var arrQrStr = fetchQueryStringParams();

alert(“First Name” + arrQrStr[‘fname’]);

alert(“Last Name” + arrQrStr[‘lname’]);

}

Hope it helps 🙂

Advertisements

How to get Object Type Codes of Entities in CRM 2011

September 8, 2011 3 comments

Hi,

In this article i have explained different ways to fetch entities “Object Type Code”

  •  Using SQL Query :-

Get Object Type codes by Sql Query

Query>

SELECT ObjectTypeCode,*

FROM

ENTITYVIEW

Using JScript  :-

  • The “ObjectTypeCode” can be extracted from Query String using JScript
  • “ObjectTypeCode” resides in “etc” query string  parameter
  • Below is the JScript statement to get “ObjectTypeCode”

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

Key Points

  • Type codes below 10,000 are reserved for OOB entities.
  • Custom entities have a value greater than or equal to 10,000.

Note:- Custom entity object type codes may change during import and are not guaranteed to be the same between systems.

Getting Object Type Code by ‘Entity Name’ using Jscript

Below script uses CRM inbuilt logic and return the entity type code (or) object type code for the given entity name.

function getObjectTypeCodeByName(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 (e) {

alert(“Error while getting ETC by Name – ” + e.description);

}

}

Hope it helps 🙂

Submit disabled field using Jscript in CRM 2011

Hi,

Below is the syntax to submit the disabled field value using JScript.

Xrm.Page.getAttribute(“{fld_id}”).setValue(“{fld_value}”);

Xrm.Page.getAttribute(“{fld_id}”).setSubmitMode(“always”)

Hope it helps 🙂