web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

field value changes after saving.

(0) ShareShare
ReportReport
Posted on by

I am facing a problem with crm forms as when i change the field "imc_totalweight" value from 50 to any other value the calculation of freight is done and after saving the calculations -the number changes back to 50 but the freight calulations are accurate according to the another inserted values.

here is my javascript code:

function launchQuoteDetailsReport() {
var rdlName = "QuoteSalesDetailsParentReport.rdl";
var reportGuid = "828227c6-c644-e211-8f68-000c295e2404";
var entityGuid = Xrm.Page.data.entity.getId();
var entityType = "1084";
var serverUrl = Xrm.Page.context.getClientUrl();
var organizationName = Xrm.Page.context.getOrgUniqueName();
var link = serverUrl + "/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=" + rdlName + "&id={" + reportGuid + "}&records=" + entityGuid + "&recordstype=" + entityType;
openStdDlg(link, null, 800, 600, true, false, null);
}
function Form_onload() {
if (Xrm.Page.ui.getFormType() == 1) {
Xrm.Page.getAttribute("effectivefrom").setValue(new Date);
Xrm.Page.getAttribute("effectivefrom").fireOnChange();
}
Xrm.Page.ui.tabs.get(4).setVisible(false);
if (Xrm.Page.ui.getFormType() == 1 || Xrm.Page.ui.getFormType() == 2) {
var mydate = new Date;
Xrm.Page.getAttribute("imc_timestamp").setValue(mydate);
}
}
function Form_onsave() {
if (Xrm.Page.ui.getFormType() == 1 || Xrm.Page.ui.getFormType() == 2) {
Xrm.Page.getAttribute("imc_calculatefreight").setSubmitMode("always");
Xrm.Page.getAttribute("imc_timestamp").setSubmitMode("always");
}
}
function imc_calculatefreight_onchange() {
var calcFreight = Xrm.Page.getAttribute("imc_calculatefreight").getValue();
if (calcFreight == true) {
var URL = "http://www.example.com/";
var zipcode = Xrm.Page.getAttribute("shipto_postalcode").getValue();
var weight = Xrm.Page.getAttribute("imc_totalweight").getValue();
var origin = "63044";
var p = Xrm.Page.getAttribute("imc_shippingfrom").getValue();
if (p == "3") {
origin = "62035";
}
if (p == "2") {
origin = "44146";
}
if (p == "4") {
origin = "92553";
}
if (p == "5") {
origin = "21230";
}
if (p == "100000000") {
origin = "32060";
}
if (p == "100000001") {
origin = "84401";
}
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load(URL + "&origin=" + origin + "&dest=" + zipcode + "&weight1=" + weight);
var error = xmlDoc.getElementsByTagName("error").item(0).text;
var strfreight = xmlDoc.getElementsByTagName("netcharges").item(0).text;
var intdays = xmlDoc.getElementsByTagName("days").item(0).text;
if (error != "") {
alert("Error ocurred retrieving freight cost:\n\n" + error);
Xrm.Page.getAttribute("freightamount").setValue(null);
Xrm.Page.getAttribute("imc_days").setValue(null);
} else {
if (freight != "") {
var freight = strfreight.replace(/\$|,/g, "");
freight = freight * 1.2 + 70.00;
Xrm.Page.getAttribute("freightamount").setValue(parseFloat(freight));
Xrm.Page.getAttribute("imc_days").setValue(parseInt(intdays));
}
}
}
}
function effectivefrom_onchange() {
var start_date = Xrm.Page.getAttribute("effectivefrom").getValue();
var end_date = Xrm.Page.getAttribute("effectiveto");
if (start_date != null && start_date != "") {
var sd_yy = start_date.getYear();
var sd_mm = start_date.getMonth();
var sd_dd = start_date.getDate();
var new_date = start_date.setMonth(start_date.getMonth() + 1);
end_date.setValue(new_date);
}
}
function billto_telephone_onchange() {
var oPhone = Xrm.Page.getAttribute("billto_telephone");
var isError = "false";
var isExtension = "false";
var vPhone = oPhone.getValue();
var rString = /[\(\)\-\. ]/g;
vPhone = vPhone.replace(rString, "");
vPhone = vPhone.replace("ext", "x");
vPhone = vPhone.replace("EXT", "x");
vPhone = vPhone.substring(0, 1) == "1" ? vPhone.substring(1, vPhone.length) : vPhone;
if (vPhone.length < 10) {
isError = "true";
} else {
var vPhone1 = vPhone.substr(0, 3);
var vPhone2 = vPhone.substr(3, 3);
var vPhone3 = vPhone.substr(6);
if (vPhone3.indexOf("x") > 0) {
isExtension = "true";
var vPhone4 = vPhone3.substr(vPhone3.indexOf("x") + 1);
vPhone3 = vPhone3.substr(0, vPhone3.indexOf("x"));
}
}
if (isError == "true" || isNaN(Math.abs(vPhone1)) || isNaN(Math.abs(vPhone2)) || (isNaN(Math.abs(vPhone3)) || vPhone3.length != 4) || isExtension == "true" && (isNaN(Math.abs(vPhone4)) || vPhone4.length > 5)) {
alert("The Phone number entered is not a valid phone number, the phone number must be 10 digits." + "\n\nThe valid format for phone numbers is (234) 567-8901 or with an extension" + "\nthe valid format is (234) 567-8901 x1234." + "\n\nExamples of valid phone numbers, which will get automatically formatted, are:" + "\n\t2345678901 \t2345678901 x1234" + "\n\t234.567.8901 \t234.567.8901 ext 1234" + "\n\t(234)567-8901\t(234)567-8901 EXT1234" + "\n\nPlease reenter the phone number in one of the above formats.\n\n");
oPhone.SetFocus();
event.returnValue = false;
return;
}
oPhone.setValue("(" + vPhone1 + ") " + vPhone2 + "-" + vPhone3 + (isExtension == "true" ? " x" + vPhone4 : ""));
}
function billto_fax_onchange() {
var oPhone = Xrm.Page.getAttribute("billto_fax");
var isError = "false";
var isExtension = "false";
var vPhone = oPhone.getValue();
var rString = /[\(\)\-\. ]/g;
vPhone = vPhone.replace(rString, "");
vPhone = vPhone.replace("ext", "x");
vPhone = vPhone.replace("EXT", "x");
vPhone = vPhone.substring(0, 1) == "1" ? vPhone.substring(1, vPhone.length) : vPhone;
if (vPhone.length < 10) {
isError = "true";
} else {
var vPhone1 = vPhone.substr(0, 3);
var vPhone2 = vPhone.substr(3, 3);
var vPhone3 = vPhone.substr(6);
if (vPhone3.indexOf("x") > 0) {
isExtension = "true";
var vPhone4 = vPhone3.substr(vPhone3.indexOf("x") + 1);
vPhone3 = vPhone3.substr(0, vPhone3.indexOf("x"));
}
}
if (isError == "true" || isNaN(Math.abs(vPhone1)) || isNaN(Math.abs(vPhone2)) || (isNaN(Math.abs(vPhone3)) || vPhone3.length != 4) || isExtension == "true" && (isNaN(Math.abs(vPhone4)) || vPhone4.length > 5)) {
alert("The Fax number entered is not a valid phone number, the phone number must be 10 digits." + "\n\nThe valid format for phone numbers is (234) 567-8901 or with an extension" + "\nthe valid format is (234) 567-8901 x1234." + "\n\nExamples of valid phone numbers, which will get automatically formatted, are:" + "\n\t2345678901 \t2345678901 x1234" + "\n\t234.567.8901 \t234.567.8901 ext 1234" + "\n\t(234)567-8901\t(234)567-8901 EXT1234" + "\n\nPlease reenter the phone number in one of the above formats.\n\n");
oPhone.SetFocus();
event.returnValue = false;
return;
}
oPhone.setValue("(" + vPhone1 + ") " + vPhone2 + "-" + vPhone3 + (isExtension == "true" ? " x" + vPhone4 : ""));
}
function shipto_telephone_onchange() {
var oPhone = Xrm.Page.getAttribute("shipto_telephone");
var isError = "false";
var isExtension = "false";
var vPhone = oPhone.getValue();
var rString = /[\(\)\-\. ]/g;
vPhone = vPhone.replace(rString, "");
vPhone = vPhone.replace("ext", "x");
vPhone = vPhone.replace("EXT", "x");
vPhone = vPhone.substring(0, 1) == "1" ? vPhone.substring(1, vPhone.length) : vPhone;
if (vPhone.length < 10) {
isError = "true";
} else {
var vPhone1 = vPhone.substr(0, 3);
var vPhone2 = vPhone.substr(3, 3);
var vPhone3 = vPhone.substr(6);
if (vPhone3.indexOf("x") > 0) {
isExtension = "true";
var vPhone4 = vPhone3.substr(vPhone3.indexOf("x") + 1);
vPhone3 = vPhone3.substr(0, vPhone3.indexOf("x"));
}
}
if (isError == "true" || isNaN(Math.abs(vPhone1)) || isNaN(Math.abs(vPhone2)) || (isNaN(Math.abs(vPhone3)) || vPhone3.length != 4) || isExtension == "true" && (isNaN(Math.abs(vPhone4)) || vPhone4.length > 5)) {
alert("The Phone number entered is not a valid phone number, the phone number must be 10 digits." + "\n\nThe valid format for phone numbers is (234) 567-8901 or with an extension" + "\nthe valid format is (234) 567-8901 x1234." + "\n\nExamples of valid phone numbers, which will get automatically formatted, are:" + "\n\t2345678901 \t2345678901 x1234" + "\n\t234.567.8901 \t234.567.8901 ext 1234" + "\n\t(234)567-8901\t(234)567-8901 EXT1234" + "\n\nPlease reenter the phone number in one of the above formats.\n\n");
oPhone.SetFocus();
event.returnValue = false;
return;
}
oPhone.setValue("(" + vPhone1 + ") " + vPhone2 + "-" + vPhone3 + (isExtension == "true" ? " x" + vPhone4 : ""));
}
function shipto_fax_onchange() {
var oPhone = Xrm.Page.getAttribute("shipto_fax");
var isError = "false";
var isExtension = "false";
var vPhone = oPhone.getValue();
var rString = /[\(\)\-\. ]/g;
vPhone = vPhone.replace(rString, "");
vPhone = vPhone.replace("ext", "x");
vPhone = vPhone.replace("EXT", "x");
vPhone = vPhone.substring(0, 1) == "1" ? vPhone.substring(1, vPhone.length) : vPhone;
if (vPhone.length < 10) {
isError = "true";
} else {
var vPhone1 = vPhone.substr(0, 3);
var vPhone2 = vPhone.substr(3, 3);
var vPhone3 = vPhone.substr(6);
if (vPhone3.indexOf("x") > 0) {
isExtension = "true";
var vPhone4 = vPhone3.substr(vPhone3.indexOf("x") + 1);
vPhone3 = vPhone3.substr(0, vPhone3.indexOf("x"));
}
}
if (isError == "true" || isNaN(Math.abs(vPhone1)) || isNaN(Math.abs(vPhone2)) || (isNaN(Math.abs(vPhone3)) || vPhone3.length != 4) || isExtension == "true" && (isNaN(Math.abs(vPhone4)) || vPhone4.length > 5)) {
alert("The Fax number entered is not a valid phone number, the phone number must be 10 digits." + "\n\nThe valid format for phone numbers is (234) 567-8901 or with an extension" + "\nthe valid format is (234) 567-8901 x1234." + "\n\nExamples of valid phone numbers, which will get automatically formatted, are:" + "\n\t2345678901 \t2345678901 x1234" + "\n\t234.567.8901 \t234.567.8901 ext 1234" + "\n\t(234)567-8901\t(234)567-8901 EXT1234" + "\n\nPlease reenter the phone number in one of the above formats.\n\n");
oPhone.SetFocus();
event.returnValue = false;
return;
}
oPhone.setValue("(" + vPhone1 + ") " + vPhone2 + "-" + vPhone3 + (isExtension == "true" ? " x" + vPhone4 : ""));
}
;

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at
    RE: field value changes after saving.

    Hi,

    Why don't you try to put some breakpoints in your code and see what is the problem after saving?

  • gdas Profile Picture
    50,091 Moderator on at
    RE: field value changes after saving.

    Hi,

    Seems you need to set field property setSubmitMode= always before save. Try once to do that and off course please debug the code see where the actually value is changing. Replace the method I have added imc_totalweight set submitmode.

    function Form_onsave() {
        if (Xrm.Page.ui.getFormType() == 1 || Xrm.Page.ui.getFormType() == 2) {
            Xrm.Page.getAttribute("imc_calculatefreight").setSubmitMode("always");
            Xrm.Page.getAttribute("imc_timestamp").setSubmitMode("always");
            Xrm.Page.getAttribute("imc_totalweight").setSubmitMode("always");  
        }
    }


  • Community Member Profile Picture
    on at
    RE: field value changes after saving.

    I gave it a try but didn't work.... i guess cross domain issue is a factor in this..this was generated after i enabled cross domain browsing in internet explorer as before that the freight calculation showed error.

  • Community Member Profile Picture
    on at
    RE: field value changes after saving.

    all calculations are good after changing values

    3107.2.png

    but after saving the form the field Total Weight goes back to 50:

    3107.2.png

  • Community Member Profile Picture
    on at
    RE: field value changes after saving.

     Hi Guillaume,

    I tried that as well didn't work

    see details :

    community.dynamics.com/.../271571

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans