Home › Forums › General discussion › calc in set field error
Tagged: Calc, Update Field Rule
- This topic has 4 replies, 2 voices, and was last updated 3 years, 11 months ago by Jeff Lynch.
-
AuthorPosts
-
-
December 22, 2020 at 20:08 #32308
I’m having the strangest thing, when I use calc:{currencyfield1}+{currencyfield2} in the set field value for a New form, it works great – 10000 + 10000 = 20000, no problem, then on edit it returns 20.00. I figured out why but I’m not sure how to solve it. basically its seeing the comma (,) inserted when the number field is saved on the edit and interpreting it as a decimal point.
To test my theory I manually removed the commas on the edit screen and it works great.
Any idea how to address this issue?
-
December 22, 2020 at 21:43 #32310
Hi,
It looks like it is struggling with the number format – can you show me how the numbers are shown in EditForm – when it evaluates to 20?Alexander
-
December 22, 2020 at 22:00 #32312
it’s inserting the commas at the thousand spot, then interprets those as decimals. As a temporary fix I created a calculated field and added them all together.
As a test I removed the commas in the edit form and when I did that it calculates the sum correctly.
-
December 23, 2020 at 10:07 #32314
The problem was related to identifying what is thousand separator and what is decimal separator (these are not the same in all languages). The function I used to convert the string (from the input field) to a number did not work properly if the number had a thousand separator but not a decimal separator – it misinterpreted the thousand separator as decimal separator.
I’ll address this in the next release, but if you could try dropping the below snippet in your Custom JS and see if it works correctly it would be great.
Best regards,
Alexanderspjs.dffs.getNumberFormat = function(){ if(spjs.dffs.data.numberFormat === undefined){ if(spjs.dffs.data.isSP07 || spjs.dffs.data.isSP10){ spjs.modal.add({ "title": "You must specify the number format", "html": "To use the function strToNum in SP 2007 or SP 2010 you must add this to your Custom JS:<pre>spjs.dffs.data.numberFormat = {\n \"ThousandSeparator\": \",\",\n \"DecimalSeparator\": \".\"\n}</pre>Change the settings to match your locale number format like it shows in the number fields in your form." }); }else{ jQspjs.ajax({ "url": _spPageContextInfo.webServerRelativeUrl + "/_api/Web/RegionalSettings", "type": "GET", "async": false, "headers": { "Accept": "application/json;odata=verbose", "content-type": "application/json;odata=verbose" }, "success": function(data){ spjs.dffs.data.numberFormat = data.d; }, "error": function(err){ // console.log(err); } }); } } return; }; spjs.dffs.strToNum = function (str) { if (typeof str === "number") { return str; } if (str === "" || typeof str !== "string") { return 0; } if(spjs.dffs.data.numberFormat === undefined){ spjs.dffs.getNumberFormat(); } str = str.split(spjs.dffs.data.numberFormat.ThousandSeparator).join(""); str = str.split(spjs.dffs.data.numberFormat.DecimalSeparator).join("."); var n = parseFloat(str); return n; };
-
December 23, 2020 at 22:33 #32322
this code worked!!! Thank you!
-
-
AuthorPosts
- You must be logged in to reply to this topic.