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;
}

Monday, November 1, 2010

Create Many to one relationship with Adding lookup in CRM entity(Account / Contract)

Create new lookup attribute

While most types of new attributes are created in the Attributes area of an entity, lookup attributes are created automatically when you create a relationship between two entities.

There are two types of relationships you can create: many-to-one and one-to-many. Because many accounts can be associated with one Contract, you’ll create a many-to-one relationship from the Account entity to the Contract entity. This is the most commonly used relationship type for a lookup because typically any number of records in the entity to which you are adding the lookup can be associated with one record in the custom entity.

1.In Microsoft CRM Dynamics CRM , click Settings, click Customization, click Customize Entities, double-click Account, and then click Relationships.

2.On the Actions toolbar, click New Many-to-1 Relationship.

3.In the Relationship: New dialog box, in the Primary Entity box, select Contract.

4.In the Display Name box, type Contract. Though this is the display name for the relationship, it is also the display name of the new lookup attribute. The Type field is set to lookup.

5.If you want this attribute to be Business Required or Recommended, select the appropriate setting in the Requirement Level box.

6.In the Relationship Behavior section, in the Type of Behavior box, select Referential.

7.Click Save and Close. This leaves the Entity: Account form open. Keep this form open, because you will use it in the next procedure.
Top of pageTop of page
Add your new lookup attribute to a form

You can position the new lookup attribute on the Account form wherever it makes most sense for your users.

1.On the Entity: Account form, under Details, click Forms and Views, and then in the list, double-click Form.

2.Select the section where you want to add the Contract lookup attribute. To select a section, click the section header, and a green line is displayed surrounding the section.

3.Click Add Fields. Your new lookup attribute appears on the list.

4.Select Contract, and then click OK.

5.Click Save, which will leave the Form: Account form open. Keep this form open, because you will use it in the next procedure.
Top of pageTop of page
Test your new lookup field

Before you publish a customization to a form, preview it in all the modes that will use the form so that you can verify that it works as you expect.

1.On the Form: Account form, on the Preview menu, click Create Form.
2.Click the Lookup button next to the Contract field. If you have created any records in the Contract entity, the list appears. Close the Lookup Records dialog box, and then, on the File menu, click Close to close the preview window.

3.On the Form: Account form, on the Preview menu, click Update Form, and then repeat step 2.
4.Click Save and Close.

5.On the Entity: Account form, click Save and Close.
Top of pageTop of page
Publish your customization

For your users to see the changes you’ve made, you must publish the customization.
•On the Customize Entities page, on the Actions toolbar, click Publish.