Wednesday, November 10, 2010

Get Parent Form Details Using Java Script In CRM 2011(Sub Grid Form)

01.Get Crm Service
function init() {

// Set Global Variables
var serverUrl = Xrm.Page.context.getServerUrl();
ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
// var Id = Xrm.Page.data.entity.getId();
retrieveAccountRecord();
}

02.Pass Parent Id (GuID) in to Service
function retrieveAccountRecord(GuId parentID ) {

//Set Request
var retrieveAccountReq = new XMLHttpRequest();
var path = ODataPath + "/mship_subscriptionmatrixSet(guid'" + parentID + "')";
retrieveAccountReq.open("GET", path, true);
retrieveAccountReq.setRequestHeader("Accept", "application/json");
retrieveAccountReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

retrieveAccountReq.onreadystatechange = function () {
retrieveAccountReqCallBack(this);
};
retrieveAccountReq.send();

}

function retrieveAccountReqCallBack(retrieveAccountReq) {
if (retrieveAccountReq.readyState == 4 /* complete */) {
if (retrieveAccountReq.status == 200) {
//Success
var retrievedAccount = JSON.parse(retrieveAccountReq.responseText).d;
var testOb = retrievedAccount.new_name; //

}

}
}

03.you can retrieve all values in retrievedAccount in Parent.


////////Apply this in Child form Load Event.....

///////To get Parent Id in Sub Grid//////////////


If you want to retrieve parent Data in Sub Grid form you can also use above.
To get parent record guid
///
01.Get server Url and get Created Form id parameter Value like Bellow.
var parentID = GetUrlParameter(); //Get Parent Page Id
parentID = parentID.substring(3, parentID.length - 3);

function GetUrlParameter() {
var id = "";
var name = "_CreateFromId";

name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);

if (results == null) {

} else {
id = results[1];
}
return id;
}

No comments:

Post a Comment