Blog Archives

How to Get the value from a CRM field

// JavaScript/JScript in CRM 2011 | CRM 2011 Training Series
    //How to Get the value from a CRM field
    var varMyValue = Xrm.Page.getAttribute(“CRMFieldSchemaName”).getValue() ;

//How to Set the value of a CRM field
Xrm.Page.getAttribute(“po_CRMFieldSchemaName”).setValue(‘My New Value’);

 **For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.

How to get Form Type using JavaScript in CRM 2011

Top_bottom banner

 

Get Form type using javascript in CRM 2011 :

When you write Java script/Jscript code on CRM forms, there will be situations where you need to trigger the script only on certain forms. This is how we get the Form Type.
In CRM 2011, there are 7 types of forms are defined.
0 – undefined
1 – Create
2 – Update
3 – Read Only
4 – Disabled
5 – Quick Create (Deprecated)
6 – Bulk Edit
The below script checks the form type and alert if the form type is of ‘Create’ form.
//Get form type
var CREATE_FORM = 1;
var type = Xrm.Page.ui.getFormType();
if(type = CREATE_FORM)
{
alert(“This is Create Form”);
}
Hope this helps!

Please share |Like in Facebook if you feel like this page is useful.

Top_bottom banner

How to Get the label of the control using Javascript?

// JavaScript/JScript in CRM 2011 | CRM 2011 Training Series
// How to Get the label of the control using Javascript?
    Xrm.Page.ui.controls.get(‘<Attribute Name>’).getLabel()
    // Get record id
    Xrm.Page.data.entity.getId()
    // set field as required based value of a check box field.
    function OnChangeBoolField()
    {
    var varBool = Xrm.Page.data.entity.attributes.get(“<Boolean Field Name>”).getValue();
    if(varBool == false)
    {
     Xrm.Page.getAttribute(“<Attribute Name>”).setRequiredLevel(“required”);
    }
    else
    {
     Xrm.Page.getAttribute(“<Attribute Name>”).setRequiredLevel(“none”);
    }
    }
**For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.

How to Get the changed data from form using Jscript?

/ JavaScript/JScript in CRM 2011 | CRM 2011 Training Series

//How to Get the changed data using Jscript?
var ChangedData = Xrm.Page.data.entity.getDataXml();

 **For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.

How to retieve data through SOAP XML using Jscript in CRM 2011

//How to retieve data through SOAP XML using Jscript in CRM 2011
if (Xrm.Page.getAttribute(“parentcustomerid”).getValue() != null) {
    //acount guid no
    var parentcustomerID = Xrm.Page.data.entity.attributes.get(“parentcustomerid”).getValue()[0].id;
    var xml = “<?xml version=’1.0′ encoding=’utf-8′?>” +
    “<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/'&#8221; +
    GenerateAuthenticationHeader() +
    “<soap:Body>” +
    “<entityName>account</entityName>” +
    “<id>” + parentcustomerID + “</id>” +
    “<columnSet xmlns:q1=’http://schemas.microsoft.com/crm/2006/Query&#8217; xsi:type=’q1:ColumnSet’>” + Read the rest of this entry

How to trigger On Save function using JavaScript?

// JavaScript/JScript in CRM 2011 | CRM 2011 Training Series

//How to trigger On Save function using JavaScript?
Xrm.Page.data.entity.save();

 **For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.

How to Compare Dates using JavaScript?

Top_bottom banner
// How to Compare Dates using JavaScript?
    function ValidateDates()
    {
    var Date1 = Xrm.Page.getAttribute(‘<Date Attribute Name1>’).getValue();
    var Date2 = Xrm.Page.getAttribute(‘<Date Attribute Name2>’).getValue();
     if(Date1 != null && Date2 != null)
     {
     if(Date1.setHours(0,0,0,0) < Date2.setHours(0,0,0,0))
     {
     alert(‘Date2 is greater than or equal to Date1’);
     }
     }
    }

Please share |Like in Facebook if you feel like this page is useful.

Top_bottom banner

How to hide a tab using JavaScript?

//How to hide a tab using JavaScript?
    //Hide/Show a tab
    Xrm.Page.ui.tabs.get(5).setVisible(false);
    Xrm.Page.ui.tabs.get(5).setVisible(true);

 **For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.

How to Call the onchange event of a field?

Top_bottom banner

//How to Call the onchange event of a field

     Xrm.Page.getAttribute(“CRMFieldSchemaName”).fireOnChange();

Please share |Like in Facebook if you feel like this page is useful.

How to Get the selected value of picklist using JavaScript?

//How to Get the selected value of picklist
    Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;

 **For CRM 2011 Training, please check out our CRM Training page. Please share |Like in Facebook if you feel like this page is useful.