Tuesday, May 5, 2015

How to update the value of parent entity field while updating child entity in ms crm 2011 using javascript

Parent Entity  to open the child entity in popup windows with selected records

function addPriceEndDate(selecteditemsid)
{
var parameters = {};
parameters["selecteditemsid_0"] = selecteditemsid;
  Xrm.Utility.openEntityForm("cel_priceenddate", null, parameters);    
}

Add the Below parameters in ribbon workbench.



From child entity we updating the parent entity fields in my case I am updating End date. Below is script.

function onPriceEndDateSave()
{
if (getQuerystring('selecteditemsid_0') != null)
{
var accountid = getQuerystring('selecteditemsid_0');
accountid = ReplaceString(accountid ,"%7b","{");
accountid = ReplaceString(accountid ,"%7d","}");
accountid = ReplaceString(accountid ,"%2c",",");
var priceids= new Array();
priceids= accountid.split(",");
for (price in priceids) {
updateRecord(priceids[price]);
}
}
}


function updateRecord(id)
{
debugger;
try
{
var price = {};
price.cel_EndDate = Xrm.Page.getAttribute("cel_priceenddate").getValue();

SDK.REST.updateRecord(
id,
price ,
"cel_price",
function () {
writeMessage("The Price record changes were saved");
},
errorHandler
);

}
catch(e)
{
alert("Failed to Execute");
}
}
function errorHandler(error) {
alert(error.message);
}
function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[[]/,"[").replace(/[]]/,"]");
var regex = new RegExp("[?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}
function ReplaceString(strString, strReplace, strReplaceWith){
if (strString != "" && strReplace != "") {
var re = new RegExp(strReplace, "gi");
var s = strString.replace(re, strReplaceWith);
return s;
}
else{
return strString;
}

}

No comments:

Post a Comment

Get files of last hour in Azure Data Factory

  Case I have a Data Factory pipeline that should run each hour and collect all new files added to the data lake since the last run. What is...