Some CRM 2011 JavaScript


//Hide Section in

Xrm.Page.ui.tabs.get(“Name of the tab”).sections.get(“Name of the section”).setVisible(true);

Xrm.Page.ui.tabs.get(“Name of the tab”).sections.get(“Name of the section”).setVisible(False);

//Force Submit method has changed to

Xrm.Page.getAttribute(“Field Name”).setSubmitMode(“always”);

//Get Selected Picklist value

var _Value = Xrm.Page.getAttribute(“Name of Picklist”).getSelectedOption().text;

//Get Entity Attributes based on ID

var context;

var serverUrl;

var ODataPath;

function Getinfo() {

    context = Xrm.Page.context;

    serverUrl = context.getServerUrl();

    ODataPath = serverUrl + “/XRMServices/2011/OrganizationData.svc”;

}

function GetID() {

    var ID = Xrm.Page.getAttribute(“Nameof ID field”).getValue()[0].id;

    RetrieveAccountRecord(ID);

}

function RetrieveAccountRecord(Id) {

    var RetrieveAccountReq = new XMLHttpRequest();

    RetrieveAccountReq.open(“GET”, ODataPath + “/AccountSet(guid'” + Id + “‘)”, true); //I am fetch account data

    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) {

            var RetrievedAccount = this.parent.JSON.parse(RetrieveAccountReq.responseText).d;

            if(RetrievedAccount.Telephone1!=null)

                Xrm.Page.getAttribute(“TargetTelephonefield”).setValue(RetrievedAccount.Telephone1);

            if(RetrievedAccount.Emailaddress1!=null)

                Xrm.Page.getAttribute(“TargetEmailfield”).setValue(RetrievedAccount.Emailaddress1);

                      }

        else {

            errorHandler(RetrievedAccount);

            alert(“Error in Fetch Account data”);

        }    }}

 Reference : Microsoft Dynamics CRM 2011 SDK

Enjoy !!!

Advertisements

5 Comments

Filed under MS CRM 2011

5 responses to “Some CRM 2011 JavaScript

  1. j0ngleur

    very nice!

    just some small errors: “retrievedAccount” is sometimes beginning with lower case but defined as “RetrievedAccount” (the same goes for “retrieveAccountReq”)

  2. Thanks for sharing such a good idea, paragraph is fastidious,
    thats why i have read it fully

  3. Helpful info. Lucky me I discovered your site unintentionally, and I’m shocked why this twist of fate didn’t happened earlier!
    I bookmarked it.

  4. Greetings! Very helpful advice in this particular article! It’s the little changes that produce the largest changes. Many thanks for sharing!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s