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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to set currency field

(0) ShareShare
ReportReport
Posted on by 775

hello,

how I set currency field if value is greater than money then the result is multiply by 2 in same field

thanx

*This post is locked for comments

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You can do this either using business rules or JavaScript, they should both work.

    If you need further help please provide more details

  • Verified answer
    kiran_rajput Profile Picture
    775 on at

    hello Aric,

    i Will get currency field new_money on contact entity

    if the money is greater than 500 then the money is multiply by 2 and assign into same field that is new_money by using plugin

    thnx

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    You can do this without plugin using JS or Business Rule.

    If you want to use a plugin, it's simple enough code:

    // Using Early binding

    decimal moneyValue = contact.Contains("new_money") ? contact.new_Money.Value : 0;

    // or Late Binding

    decimal moneyValue = contact.Contains("new_money") ? ((Money)(contact["new_money"])).Value : 0;

    if (moneyValue > 500)

      moneyValue = moneyValue * 2;

    // Call function to Update Money Value

    UpdateMoneyValue (Guid contactId, decimal moneyValue)

    // Function to Update Money Value

    private void UpdateMoneyValue(Guid contactId, decimal moneyValue)

    {

      Entity contact = new Entity("contact");

      contact.Id = contactId;

      contact["new_money"] = new Money(moneyValue);

      service.Update(contact); // Inside try..catch block

    }

  • Verified answer
    kiran_rajput Profile Picture
    775 on at

    Hello,

     Aric,

    I write this code on message=Update, primary entity=contact, stage=post-operation

    6866.error.PNG

    and i am getting this error,

    6866.error.PNG

  • Verified answer
    Krishna potdar Profile Picture
    317 on at

    Hi Kiran,

    You have to write the Context.depth in the plugin code.

    after this line You have to write the Context.depth

    decimal pricevalue=money.value;

    if(context.depth=1)

    {

    }

    please mark as Verified if it works.

  • Verified answer
    kiran_rajput Profile Picture
    775 on at

    thanx , krishna

    i have done it by using context.depth

  • Saddamk206 Profile Picture
    777 on at

    Get and Set Currency(Money) using C#

    Get : -

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

    Post : -

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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans