Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

SDK.REST.updateRecord not updating Currency field ?

Posted on by 1,431

Hi Geeks,

From a web resource I m updating OpportunityProduct records.
I can update string and number fields but can't update currency field.It is not showing any
error but just don't update value and the value always remains 0.00.

Am I missing something or doing wrong ? Below is my code.

 function UpdateRecord(guid, description, quantity, manualdiscountamount, priceperunit) {
             
            var entity = {};
            if (description != null && description !== "")
                entity.ProductDescription = description;
            entity.Quantity = parseFloat(quantity).toFixed(0);
            if (priceperunit !== null && priceperunit !== 0)
                entity.PricePerUnit = {
                    Value: "45.66"
                };
            if (priceperunit !== null && priceperunit !== 0)
                entity.PricePerUnit_Base = {
                    Value: parseFloat(eval(priceperunit)).toFixed(2)  
                };
            
              if (guid !== undefined) {
                 SDK.REST.updateRecord(guid, entity, "OpportunityProduct", function () {
                    alert("Completed");


                }, function (error) {
                    Xrm.Utility.alertDialog(error.message);
                    alert("Error");
                });
            }

I have tried setting currency value in different ways one above (by hard coding) and also as below:

Value: parseFloat(manualdiscountamount).toFixed(2) !== NaN ? parseFloat(manualdiscountamount).toFixed(2) : "0.0"


Or:

Value: parseFloat(eval(priceperunit))


Kindly guide if you can.

*This post is locked for comments

  • Suggested answer
    Haansi Profile Picture
    Haansi 1,431 on at
    RE: SDK.REST.updateRecord not updating Currency field ?

    Thanks Nadeeja, I appreciate your response.

    I think both approaches would be fine, later I figured out the issue. It is an existing project and a plugin was stopping it. Unfortunately I did not have code but I disabled the plugin and my code started working.

    Thanks again for replying.

  • Suggested answer
    Nadeeja Bomiriya Profile Picture
    Nadeeja Bomiriya 6,804 on at
    RE: SDK.REST.updateRecord not updating Currency field ?

    Hi Yawer,

    Have you tried without the below if condition?

    if (priceperunit !== null && priceperunit !== 0)

                   entity.PricePerUnit_Base = {

                       Value: parseFloat(eval(priceperunit)).toFixed(2)  

                   };

    Just the below code should work.

    if (priceperunit !== null && priceperunit !== 0)

                   entity.PricePerUnit = {

                       Value: "45.66"

                   };

    msdn.microsoft.com/.../gg309549(v=crm.7).aspx

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans