Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to set currency field to an empty string with a plugin

Posted on by 215

Hi guys,

So i have a lookup to transaction currency that is being populated through another entity and this works fine.

Now the problem is that when i delete the other entity i also need to return the currency to an empty name.

Bellow is the code i have tried.

Entity productOffer = service.Retrieve(Entity_Name, entityRef.Id, new ColumnSet(true));
                    Entity vintage = service.Retrieve(Entity_Name, productOffer.GetAttributeValue<EntityReference>(EC.Product_Offer.Vintage).Id, new ColumnSet(true));
                    decimal money = 0;
                    EntityReference currency = vintage.GetAttributeValue<EntityReference>(EC.Vintage.Currency);

                    currency.Name = "";
                    vintage.Attributes["new_netpriceperbottle"] = new Money(money);
                    vintage.Attributes["transactioncurrencyid"] = new EntityReference("transactioncurrency", currency.Id);
                    service.Update(vintage);


When i am debugging everything goes ok and the lookup in vintage to transaction currency returns (transactioncurrency.Name = null). But on CRM the value remains.

Any advice?

*This post is locked for comments

  • Saddamk206 Profile Picture
    Saddamk206 777 on at
    RE: How to set currency field to an empty string with a plugin

    Get and Set Currency(Money) using C#

    Get : -

    var moneyValue = ((Money)item.Attributes[attributeName]).Value;

    Post : -

    newSalesOrder[attributeName] = new Money((decimal)moneyValue);

    Set Null Value:-

    newSalesOrder[attributeName] = Null;

     

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: How to set currency field to an empty string with a plugin

    Got it working i should have given null to the money value i am passing.

  • Filip Vanchevski Profile Picture
    Filip Vanchevski 215 on at
    RE: How to set currency field to an empty string with a plugin

    I tried, but i get a Business Process Error The currency cannot be null.

  • Verified answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: How to set currency field to an empty string with a plugin

    you need to set to null to clear the field

    vintage["transactioncurrencyid"] = null;

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