Answered by:
CRM 2011 javascript get currency field from retrieveMultiple/fetch (XrmSvcToolkit.js)

Question
-
Hi!
I have been struggling A LOT with this issue:-)
Problem is: I have made a new button with a JavaScript function using XrmSvcToolkit.retrieveMultiple function. I'm getting the rows I want but there is a Currency field there I can't read... it says "You must enter a number between -100000000... and 10000000...". Reading other fields is no problem, therefore I'm sure its the Currency field that causes me trouble.
Have also tried XrmSvcToolkit.fetch... same problem, can't get the value/sum. I know for sure the xml is OK.
Please help me, I'm stuck again:-)
RetrieveMultiple code:
function recalculateestimatedvalue(opportunityid) { var opportunityEV = Xrm.Page.getAttribute("estimatedvalue").getValue(); //alert("opportunityEV 1 : " + opportunityEV); opportunityEV = 0; var opportunityGuid = opportunityid.replace("{", "'").replace("}", "'"); var filterQuery = "?$filter=statecode/Value eq 0 and eeg_OpportunityId/Id eq guid" + opportunityGuid; XrmSvcToolkit.retrieveMultiple({ entityName: "eeg_produktlinje", async: false, odataQuery: filterQuery, successCallback: function (result) { for (i = 0; i < result.length; i++) { opportunityEV = opportunityEV + result[i].eeg_Sum.value; } //alert("opportunityEV 2 : " + opportunityEV); Xrm.Page.getAttribute("estimatedvalue").setValue(opportunityEV); }, errorCallback: function (error) { alert("Reculculating estimated value failed: " + error.description); } }); }
Fetch code:
function recalculateestimatedvalue(opportunityid) { //var opportunityGuid = opportunityid.replace("{", "'").replace("}", "'"); var fetchXml = "<fetch mapping='logical' distinct='false' aggregate='true'>" + "<entity name='eeg_produktlinje'>" + "<attribute name='eeg_sum' aggregate='sum' alias='evSum'/>" + "<filter type='and' >" + "<condition attribute='eeg_opportunityid' operator='eq' value='" + opportunityid + "'/>" + "</filter>" + "</entity>" + "</fetch>"; var opportunityEV = Xrm.Page.getAttribute("estimatedvalue").getValue(); opportunityEV = 0; XrmSvcToolkit.fetch({ fetchXml: fetchXml, async: false, successCallback: function (result) { if (result != null) { Xrm.Page.getAttribute("estimatedvalue").setValue(result.evSum); } }, errorCallback: function (error) { alert("Reculculating estimated value failed: " + error.description); } }); }
BR Knut MyreTuesday, June 24, 2014 9:49 AM
Answers
-
I found the solution:-)
function recalculateestimatedvalue(opportunityid) { var fetchXml = "<fetch mapping='logical' aggregate='true'>" + "<entity name='eeg_produktlinje'>" + "<attribute name='eeg_sum' aggregate='sum' alias='evSum'/>" + "<filter type='and' >" + "<condition attribute='eeg_opportunityid' operator='eq' value='" + opportunityid + "'/>" + "</filter>" + "</entity>" + "</fetch>"; XrmSvcToolkit.fetch({ fetchXml: fetchXml, async: false, successCallback: function (result) { if (result != null) { Xrm.Page.getAttribute("estimatedvalue").setValue(parseFloat(eval(result.entities[0].evSum.Value))); } }, errorCallback: function (error) { alert("Reculculating estimated value failed: " + error.description); } }); }
Cheers!Wednesday, June 25, 2014 6:30 AM
All replies
-
Try:-
Xrm.Page.getAttribute("estimatedvalue").setValue(parseFloat(result.evSum));
Regards Faisal
Tuesday, June 24, 2014 1:10 PM -
Hi Faisal! Thanks for responding!!
Its says "You must enter a number between...".
The funny thing is that if I select f.ex. the attribute "exchangerate"(instead of eeg_sum and turn aggregation off), it works perfect With result.entities[0].exchangerate. Then I tried With eeg_sum(without aggregation), same problem.
It seems to me the customized attribute is unknown in some way...
BR Knut
Tuesday, June 24, 2014 2:36 PM -
Hi again!
I tried to sum from another customized entity/attribute(decimal number), worked just fine With result.entities[0].evSum. So my conclusion must be the Currency type is my challenge.
BR Knut
Wednesday, June 25, 2014 6:18 AM -
I found the solution:-)
function recalculateestimatedvalue(opportunityid) { var fetchXml = "<fetch mapping='logical' aggregate='true'>" + "<entity name='eeg_produktlinje'>" + "<attribute name='eeg_sum' aggregate='sum' alias='evSum'/>" + "<filter type='and' >" + "<condition attribute='eeg_opportunityid' operator='eq' value='" + opportunityid + "'/>" + "</filter>" + "</entity>" + "</fetch>"; XrmSvcToolkit.fetch({ fetchXml: fetchXml, async: false, successCallback: function (result) { if (result != null) { Xrm.Page.getAttribute("estimatedvalue").setValue(parseFloat(eval(result.entities[0].evSum.Value))); } }, errorCallback: function (error) { alert("Reculculating estimated value failed: " + error.description); } }); }
Cheers!Wednesday, June 25, 2014 6:30 AM