Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

Dire need of a conversion fron XRM to a script that works in D365

Posted on by Microsoft Employee

We are having an issue with an script that is rather large and not writen by me but from a former person that is no longer working with us 

I do now that Xrm.Page is being depricated but i do not have any idea of how to convert this script to something that works 

function setEstRevenue() {
debugger;
//setTimeout("refresh();", 2500);
//GridOnloadFunction();
RetrieveSubGridRecords();
Xrm.Page.getAttribute("jvs_probability").addOnChange(this.probability_OnChange);

//NEMELY: 2018-06-14
//We need to set submit mode of read only fields to ensure they get saved to the database
Xrm.Page.getAttribute("new_jvs_estserviceqty").setSubmitMode("always");
Xrm.Page.getAttribute("new_estservicehours").setSubmitMode("always");
//Filip: 2018-09-13
Xrm.Page.getAttribute("jvs_estlicenserevenue").setSubmitMode("always");
Xrm.Page.getAttribute("estimatedvalue").setSubmitMode("always");

}

function refresh() {
Xrm.Page.getControl('opportunityproductsGrid').addOnLoad(RetrieveSubGridRecords);
}

function RetrieveSubGridRecordsUpdate()
{
RetrieveSubGridRecords();
}

function RetrieveSubGridRecords() {

if (document.getElementById("opportunityproductsGrid")) {
Xrm.Page.ui.controls.get("new_estservicehours").setDisabled(false);
Xrm.Page.ui.controls.get("new_jvs_estserviceqty").setDisabled(false);
var grid = document.getElementById("opportunityproductsGrid").control;
Xrm.Page.getAttribute("new_estservicerevenue").setValue(0);
Xrm.Page.getAttribute("jvs_estlicenserevenue").setValue(0);
var licRev = Xrm.Page.getAttribute("jvs_estlicenserevenue").getValue();
var serRev = Xrm.Page.getAttribute("new_estservicerevenue").getValue();
var serQty = 0;
var serHrs = 0;


var probability = parseInt(Xrm.Page.getAttribute("jvs_probability").getText(),10);
var weiglicrev = 0;
var weigserrev = 0;
var weighrs = 0;

var ids = grid.get_allRecordIds();
for (var i = 0, length = ids.length; i < length; i++) {
var url = Xrm.Page.context.getClientUrl();
var guid = ids[i];

guid = guid.replace('{', '').replace('}', '');
var odataSelect = url + "/XRMServices/2011/OrganizationData.svc/OpportunityProductSet(guid'" + guid + "')";
var PrdID = AjaxExecute(odataSelect, 1);
odataSelect = url + "/XRMServices/2011/OrganizationData.svc/ProductSet(guid'" + PrdID + "')";

//window.prompt('url', odataSelect);
var PrdType = AjaxExecute(odataSelect, 2);
//alert(PrdType);
//alert(parseFloat(grid.getCellValue('extendedamount', ids[i]).replace(/[^0-9\.]+/g, "")));
// alert(grid.GetRecordsFromInnerGrid()[i][3].cells[9].innerText.replace(/[^0-9\.]+/g, ""));
// var grid = document.getElementById("opportunityproductsGrid").control;
// //for (var rowNo = 0; rowNo < grid.GetRecordsFromInnerGrid().length; rowNo++) {
if (grid.getCellValue('primaryunit', ids[i])== 'Day'){
//alert((grid.getCellValue('primaryunit', ids[i])));
serHrs=serHrs + parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, "")) * 8;
serQty = serQty + parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, ""));
//alert(parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, "")));
//alert(parseInt(grid.getCellValue('extendedamount', ids[i]).replace(/[^0-9\.]+/g, "")));

}
if (grid.getCellValue('primaryunit', ids[i])== 'Half Day'){
//alert((grid.getCellValue('primaryunit', ids[i])));
serHrs=serHrs + parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, "")) * 4;
serQty = serQty + parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, ""));

}
if (PrdType == undefined ){
serRev = serRev + parseInt(grid.getCellValue('extendedamount', ids[i]).replace(/[^0-9\.]+/g, ""));
// serQty = serQty + parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, ""));
//alert('Wirte-In');
}

if ((PrdType == '100000000') || (PrdType == '918990000') || (PrdType == '918990001') || (PrdType == '918990003') || (PrdType == '918990002') || (PrdType == '5')) {
licRev = licRev + parseInt(grid.getCellValue('extendedamount', ids[i]).replace(/[^0-9\.]+/g, ""));
//alert('Lic');
}
if ((PrdType == '6') || (PrdType == '3')) {
serRev = serRev + parseInt(grid.getCellValue('extendedamount', ids[i]).replace(/[^0-9\.]+/g, ""));
//serQty = serQty + parseInt(grid.getCellValue('quantity', ids[i]).replace(/[^0-9\.]+/g, ""));
//alert('Ser');
}



//// }

}
Xrm.Page.getAttribute("estimatedvalue").setValue(0);

licRev = (licRev / 100);
serRev = (serRev / 100);
// serQty = (serQty / 10 );
//alert(serQty);
if (licRev > 0)
Xrm.Page.getAttribute("jvs_estlicenserevenue").setValue(licRev);
if (serRev > 0){
Xrm.Page.getAttribute("new_estservicerevenue").setValue(serRev);
Xrm.Page.getAttribute("jvs_estservicerevenue").setValue(serRev);
Xrm.Page.getAttribute("new_jvs_estserviceqty").setValue(serQty);
}
if (serRev+licRev > 0)
Xrm.Page.getAttribute("estimatedvalue").setValue(serRev+licRev);
if (serHrs > 0)
Xrm.Page.getAttribute("new_estservicehours").setValue(serHrs);
//Xrm.Page.data.save();
Xrm.Page.ui.controls.get("new_estservicehours").setDisabled(true);
Xrm.Page.ui.controls.get("new_jvs_estserviceqty").setDisabled(true);
}
else {
setTimeout("RetrieveSubGridRecords();", 2500);
}

if (probability > 0)

{
weiglicrev = licRev * (probability/100)
weigserrev = serRev * (probability/100)
weighrs = serHrs * (probability/100)
Xrm.Page.getAttribute("new_weightedlicenserevenue").setValue(weiglicrev);
Xrm.Page.getAttribute("new_weightedservicerevenue").setValue(weigserrev);
Xrm.Page.getAttribute("new_weightedhours").setValue(weighrs);
}

if (document.getElementById("opportunityproductsGrid")){
var grid1 = document.getElementById("opportunityproductsGrid").control;
var ids1 = grid1.get_allRecordIds();
if (ids1.length > 0) {
Xrm.Page.data.save();
}
}

}

function AjaxExecute(odataSelect, flag) {
var retrieveResult = new XMLHttpRequest();
var url = odataSelect;
retrieveResult.open("GET", url, false);
retrieveResult.setRequestHeader("Accept", "application/json");
retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveResult.send();

if (retrieveResult.readyState == 4) //complete
{
if (retrieveResult.status == 200) {
var retrieved = JSON.parse(retrieveResult.responseText).d;
//var Result = retrieveResult.d.ProductId.Id;
//Product ID from Opportunity product
if (flag == 1)
return retrieved.ProductId.Id;
//Product Type from Product
if (flag == 2)
return retrieved.ProductTypeCode.Value

}
}
}

function probability_OnChange()
{
debugger;
var probability= parseInt(Xrm.Page.getAttribute("jvs_probability").getText(),10);
var weiglicrev = 0;
var weigserrev = 0;

if (probability > 0)
{
weiglicrev = Xrm.Page.getAttribute("jvs_estlicenserevenue").getValue() * (probability/100)
weigserrev = Xrm.Page.getAttribute("jvs_estservicerevenue").getValue() * (probability/100)
weighrs = Xrm.Page.getAttribute("new_estservicehours").getValue() * (probability/100)

Xrm.Page.getAttribute("new_weightedlicenserevenue").setValue(weiglicrev);
Xrm.Page.getAttribute("new_weightedservicerevenue").setValue(weigserrev);
Xrm.Page.getAttribute("new_weightedhours").setValue(weighrs);
}
}

Is there any help to get with this kind of post for someone that is not used to scripts inside of D365 and was just assigned to take over the role as the D365 Administrator?

  • Charles Abi Khirs Profile Picture
    Charles Abi Khirs 3,569 on at
    RE: Dire need of a conversion fron XRM to a script that works in D365

    Hello,

    You have to pass the execution context as a first parameter to your function called from the form event and in your function, get the formcontext and use it instead of the Xrm.Page reference of your script file.

    Here is a link for more details blog.aggregatedintelligence.com/.../xrmpage-is-deprecatedwhat-to-do-in-v9.html

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans