My Photo

Microsoft Dynamics 365

Official Blog for Microsoft Dynamics Functional and Technical Solutions....
Browsing Category " JAVASCRIPT "

Passing URL to Iframe , Get and Set url to iframe using javascript in mscrm 2011



//Passing URL to Iframe
function iffffff() {

    var IFrame = Xrm.Page.ui.controls.get( "IFRAME_iframes" );
    //url value will  be saved in Url variable
    var Url = IFrame.getSrc();
    alert(Url);
    //add new url or add subs to the existing
    var trget = Url + "/movie" ;
    alert(trget);

USE HTML CODE USING JAVASCRIPT IN MSCRM 2011 , MSCRM 2013



function pwd_onchange() {
    var fieldTable1 = Xrm.Page.getAttribute( "new_password").getValue();
    fieldTable1.innerHTML = '<input tabIndex="1050" class="ms-crm-Text" id="new_password" style="ime-mode: auto;"  type="password" maxLength="100" _events="[object Object]" control="[object Object]" attrName="new_password" req="0"/>';
    Xrm.Page.getAttribute("new_password" ).setValue(Xrm.Page.getAttribute("new_password").innerHTML);
}

FORM VALIDATION ( MOBILE , PHONE NO , ZIPCODE ) USING JAVASCRIPT IN MSCRM 2011 , 2013

//mobile number field
function permanentnumber() {
    var mob = Xrm.Page.getAttribute( "Filedname").getValue();
    var length = mob.length;
    if (length < 10 || length > 10) {
        alert( "Please Enter 10 Digit Number:" );
        Xrm.Page.getAttribute( "Filedname").setValue(null );
        return true;
    }
    if (mob > 31 && (mob < 48 || mob > 57)) { }
    else {
        alert( "Please Enter 10 Digit Number:" );

CALCULATE NO OF MONTHS ( FIELD DATE - TODAY ) USING JAVASCRIPT IN MS CRM 2011 , 2013

On
/// <reference path="XrmPage-vsdoc.js" />
function calMonths() {
    //get the startdate field value in variable
    var startday = xrm.page.getAttribute( "fieldname").getValue();
    // get todays date in variable
    var today = new date();
    // get the value of one day in (mili_second * second * min * hours)
    var one_dat = 1000 * 60 * 60 * 24;
    // get no of days in month
    var one_month = 30;

CHANGE FIELD LABEL USING JAVASCRIPT IN MSCRM 2011 ,2013

//To Change Label When Fund Transfer Changes In Account Type
function FundTransferInAccountType() {
    var type = Xrm.Page.getAttribute( "new_accounttype").getValue();
    if (type == 100010003) {
        var FundTransfer = Xrm.Page.getAttribute( "new_fundtransfer").getValue();
        function changeFieldLabel(fieldName, newLabel) {
            var field = crmForm.all[fieldName + "_c"];

AUTO GENERATE END DATE USING JAVASCRIPT IN MSCRM 2011 , 2013

//Automatic generation of end date

function EndDateGeneration() {
    var NewDate = new Date(Xrm.Page.getAttribute( "new_startdate").getValue());
    if (NewDate.getMonth() < 3) {
        DateYear = NewDate.getYear();
    }
    else if (NewDate.getMonth() > 2) {
        DateYear = NewDate.getYear() + 1;

Date Validation (COMPARING DATES / GET YEAR , MONTHS AND DATE) USING JAVASCRIPT IN MSCRM 2011 , 2013

//ending Date Validation On starting Date Change
function endingDateValidation() {
    var startingDate = new Date(Xrm.Page.getAttribute("new_startingdate" ).getValue());
    var endingDate = new Date(Xrm.Page.getAttribute( "new_endingdate").getValue());
    var ExDate = Xrm.Page.getAttribute( "new_endingdate").getValue();
    if (ExDate != null) {
        if (startingDate.getYear() == endingDate.getYear()) {
            if ((startingDate.getMonth() + 1) == (endingDate.getMonth() + 1)) {
                if (startingDate.getDate() >= endingDate.getDate()) {
                    alert( "Please Enter Valid Starting Date" );

CALCULATE TIME AND DATE DIFFERENCE BETWEEN TWO USING JAVASCRIPT IN MSCRM 2011 , 2013

//Time Diffrence and logics

function ontimefrom() {
    var currentTime = new Date();
    var timefrom = Xrm.Page.getAttribute( "new_timefrom").getValue();
    //alert(currentTime);
    //alert(timefrom);
    diff(timefrom, currentTime);
}

function diff(timefrom, currentTime) {
    //debugger;
    var one_hour = 1000 * 60 * 60;

SET THE FIELD REQUIRED / MANDATORY USING JAVASCRIPT IN MSCRM 2011 , 2013

function eventtypechange()
{
var m =Xrm.Page.getAttribute("typecode").getValue();
if(m==3)
{
Xrm.Page.getAttribute("msa_street1").setRequiredLevel("required");
Xrm.Page.getAttribute("msa_stateprovince").setRequiredLevel("required");
Xrm.Page.getAttribute("msa_city").setRequiredLevel("required");
Xrm.Page.getAttribute("msa_zippostalcode").setRequiredLevel("required");

HIDE TABS IN AN ENTITY USING JAVASCRIPT IN MSCRM 2011 , 2013


function
 BalanceAccountTypeChange() {
    var GenralAccount = 100010002;
    var Bank = 100010003;

    var balance_account = Xrm.Page.data.entity.attributes.get("new_balanceaccounttype" ).getValue();
    switch (balance_account) {
        case GenralAccount:
            Xrm.Page.ui.tabs.get("GeneralJournalBatchesDetails" ).sections.get( "BalanceAccountTypeBank").setVisible( false);
            Xrm.Page.ui.tabs.get("GeneralJournalBatchesDetails" ).sections.get( "BalanceAccountTypeGeneralAccount").setVisible( true);
            break;
        case Bank:
            Xrm.Page.ui.tabs.get("GeneralJournalBatchesDetails" ).sections.get( "BalanceAccountTypeBank").setVisible( true);
            Xrm.Page.ui.tabs.get("GeneralJournalBatchesDetails" ).sections.get( "BalanceAccountTypeGeneralAccount").setVisible( false);
            break;
        default:
            Xrm.Page.ui.tabs.get("GeneralJournalBatchesDetails" ).sections.get( "BalanceAccountTypeBank").setVisible( false);
            Xrm.Page.ui.tabs.get("GeneralJournalBatchesDetails" ).sections.get( "BalanceAccountTypeGeneralAccount").setVisible( false);
            break;
    }
}
// null values for feilds on balance account type change
function BalanceAccountTypeNullonchange() {
    Xrm.Page.getAttribute( "new_generalaccount" ).setValue(null );
    Xrm.Page.getAttribute( "new_bankaccount" ).setValue(null );
}

SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

ODATA : get and set value from one entity to another (On change of look up) USING ODATA JAVASCRIPT IN MSCRM 2011 , 2013

On

function employeeonchange() {
    //debugger;
    //alert('hi');
    var lookup = new Array();
    lookup = Xrm.Page.getAttribute("new_employeename").getValue();
    if (lookup != null) {
        var name = lookup[0].name;
        var id=lookup[0].id;
    }

   //alert(name);
    oDataSelect = "http://192.168.1.96/zElite/xrmservices/2011/OrganizationData.svc/new_employeeSet?$select=new_EmployeeCode,new_name";

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: oDataSelect,
        beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, XmlHttpRequest) {
            ProcessReturnedEntity(data.d.results);
           
        },
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
        }
    });
    function ProcessReturnedEntity(OneEntity) {
  
        for (var i = 0; i <= 100000; i++) {
            var oneEntity = OneEntity[i];
            names = oneEntity.new_name;
       //   alert(names);
            if (name == names) {
                var code = oneEntity.new_EmployeeCode;
                Xrm.Page.getAttribute("new_employeecode").setValue(code);
              //  alert(names);
            }
        }

    }

}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012 

DATE VALIDATION ( GET DATE , MONTH AND YEAR FROM AN FIELD) USING JAVASCRIPT IN MSCRM 2011 , 2013

function onjoiningdate()
{
//get the value of date of joining
var startday=Xrm.Page.getAttribute("new_joiningdate").getValue();

var today=new Date();
var one_day=1000*60*60*24;
var one_month=30;
var one
var starttime=startday.getTime();
var currenttime=today.getTime();
//alert(starttime);
//alert(currenttime);
var difference = Math.abs(currenttime - starttime);
//alert(difference);
noofdays=Math.round(difference/one_day)
noofmonths=Math.round(noofdays/one_month);
//alert(noofdays);
//alert(noofmonths);
Xrm.Page.getAttribute("new_loyaltyduration").setValue(noofmonths);
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012

COPY MULTIPLE FIELD VALUES TO ANOTHER FIELDS USING JAVASCRIPT MS CRM 2011 , 2013


//When Both Address are same

function WhenSameAddress()
{

var check = Xrm.Page.getAttribute("new_bothaddressaresame").getValue() ;
if(check==true)
{
//Get Values from Correspondence Address
var street1 = Xrm.Page.getAttribute("new_castreet1").getValue() ;
var street2 = Xrm.Page.getAttribute("new_castreet2").getValue() ;
var street3 = Xrm.Page.getAttribute("new_castreet3").getValue() ;
var country = Xrm.Page.getAttribute("new_cacountry").getValue() ;
var state = Xrm.Page.getAttribute("new_castate").getValue() ;
var city= Xrm.Page.getAttribute("new_cacity").getValue() ;
var pincode = Xrm.Page.getAttribute("new_capincode").getValue() ;
//alert(street1 + street2 + street3);
//Set values to permanent Address

Xrm.Page.getAttribute("new_pastreet1").setValue(street1);
//Xrm.Page.getControl("new_pastreet1").setFocus(true);
Xrm.Page.getAttribute("new_pastreet2").setValue(street2);
Xrm.Page.getAttribute("new_pastreet3").setValue(street3);
Xrm.Page.getAttribute("new_pacountry").setValue(country);
Xrm.Page.getAttribute("new_pastate").setValue(state);
Xrm.Page.getAttribute("new_pacity").setValue(city);
Xrm.Page.getAttribute("new_papincode").setValue(pincode);



}
else
{
Xrm.Page.getAttribute("new_pastreet1").setValue(' ');
//Xrm.Page.getControl("new_pastreet1").setFocus();
Xrm.Page.getAttribute("new_pastreet2").setValue(' ');
Xrm.Page.getAttribute("new_pastreet3").setValue(' ');
Xrm.Page.getAttribute("new_pacountry").setValue();
Xrm.Page.getAttribute("new_pastate").setValue();
Xrm.Page.getAttribute("new_pacity").setValue();
Xrm.Page.getAttribute("new_papincode").setValue();


}
}


SOURCE : JUST2CODE.IN
Subscribe to our YouTube channel : https://www.youtube.com/user/TheRussell2012