A picture is worth a thousand words…. This is why we created CRM Rules…..

 

Which would you rather do? Fill out a simple form like this?

Fill out the form to Copy Fields

Fill out the form to Copy Fields

 

OR WRITE THIS CODE TO DO THE SAME THING?

 

NEWCRMRules.NEW_Estimate.CopyMarketRatewhenApartmentRateselected = function ()
{
/***********************************************************************
/**
/** Description: Copy Market Rate when Apartment Rate selected
/**
/** Rule Type is ifthenelse
/**
/** Code Produced by CRM Rules!
/** Rule Generated at:12/11/2013 1:04:43 PM By CRM Rules! Version:2011.4.15
/**
***********************************************************************/
var NEW_apartmentmarketrateid=null;
var NEW_apartmentmarketrateidattribute = Xrm.Page.getAttribute(“NEW_apartmentmarketrateid”);
if NEW_apartmentmarketrateidattribute!=null) {
NEW_apartmentmarketrateid = Xrm.Page.getAttribute(“NEW_apartmentmarketrateid”).getValue();
}

var NEW_apartmentmarketrateidSLU = null;
if (NEW_apartmentmarketrateid!= null){
NEW_apartmentmarketrateidSLU = NEW_apartmentmarketrateid[0].name;
}

if (NEWCRMRules.NEW_Estimate.NEW_apartmentmarketrateidSLUWAS != NEW_apartmentmarketrateidSLU)
{
var NEW_apartmentmarketrateid= Xrm.Page.getAttribute(“NEW_apartmentmarketrateid”).getValue();
if (NEW_apartmentmarketrateid != null){
NEWCRMRules.NEW_Estimate.getCopyMarketRatewhenApartmentRateselectedNEW_apartmentmarketrateidLookupData (NEW_apartmentmarketrateid[0].id);
}
else {
Xrm.Page.getAttribute(“NEW_aptmarketrate”).setValue(null);
}
}
};
NEWCRMRules.NEW_Estimate.getCopyMarketRatewhenApartmentRateselectedNEW_apartmentmarketrateidLookupData = function (NEW_apartmentmarketrateid) {
NEWCRMRules.NEW_Estimate.retrieveCopyMarketRatewhenApartmentRateselectedNEW_apartmentmarketrateidData(NEW_apartmentmarketrateid);
};
NEWCRMRules.NEW_Estimate.retrieveCopyMarketRatewhenApartmentRateselectedNEW_apartmentmarketrateidData = function(NEW_apartmentmarketrateid) {
var retrieveNEW_apartmentmarketrateidInfoReq = new XMLHttpRequest();
var request = VSC.GlobalFunctions._getServerUrl(“ODATA”) + “/NEW_apartmentmarketrateSet?$select=NEW_ApartmentRate&$filter=NEW_apartmentmarketrateId eq guid’” + NEW_apartmentmarketrateid + “‘”;
retrieveNEW_apartmentmarketrateidInfoReq.open(“GET”,request , true);
retrieveNEW_apartmentmarketrateidInfoReq.setRequestHeader(“Accept”,”application/json”);
retrieveNEW_apartmentmarketrateidInfoReq.setRequestHeader(“Content-Type”,”application/json; charset=utf-8″);
retrieveNEW_apartmentmarketrateidInfoReq.onreadystatechange = function () {NEWCRMRules.NEW_Estimate.retrieveCopyMarketRatewhenApartmentRateselectedNEW_apartmentmarketrateidInfoReqCallBack(this); };
retrieveNEW_apartmentmarketrateidInfoReq.send();
};
NEWCRMRules.NEW_Estimate.retrieveCopyMarketRatewhenApartmentRateselectedNEW_apartmentmarketrateidInfoReqCallBack= function (retrieveNEW_apartmentmarketrateidInfoReq) {
if (retrieveNEW_apartmentmarketrateidInfoReq.readyState == 4 /* complete */) {
if (retrieveNEW_apartmentmarketrateidInfoReq.status == 200) {
//Success
var retrieveNEW_apartmentmarketrateidInfo = window.JSON.parse(retrieveNEW_apartmentmarketrateidInfoReq.responseText).d;
if (retrieveNEW_apartmentmarketrateidInfo.results[0] != null) {
//check to see if the control is on the form before you try to setvalue on it
if (Xrm.Page.getAttribute(“NEW_aptmarketrate”) != null){
if (retrieveNEW_apartmentmarketrateidInfo.results[0].NEW_ApartmentRate != null) {
var NEW_ApartmentRatetst = retrieveNEW_apartmentmarketrateidInfo.results[0].NEW_ApartmentRate;
if (NEW_ApartmentRatetst !=null) {
Xrm.Page.getAttribute(“NEW_aptmarketrate”).setValue(parseFloat(NEW_ApartmentRatetst.Value));
} else {
Xrm.Page.getAttribute(“NEW_aptmarketrate”).setValue(null);
}
Xrm.Page.getAttribute(“NEW_aptmarketrate”).fireOnChange();
VSC.GlobalFunctions.setSubmitMode(“NEW_aptmarketrate”,”always”);
} else {
Xrm.Page.getAttribute(“NEW_aptmarketrate”).setValue(null);
}
}
} else {
alert (‘No records were returned from the copy function, please contact your administrator’)
}
} else {
//Failure
VSC.GlobalFunctions.errorHandler(retrieveNEW_apartmentmarketrateidInfoReq);
}
}
VSC.GlobalFunctions.fireOnChange(“NEW_aptmarketrate”,true);
};