Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Error when retrieve an empty money data type

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I keep getting an error says "The given key was not present in the dictionary" when trying to retrieve a record with empty money field. 

decimal estRevBase = ((Money)cloudent["estimatedvalue"]).Value;

Above code is succes when the money field is not empty. But when money field is empty, 
it's returning an error.

I tried using 

decimal ?

and Convert the decimal to string, to check wether the estrevbase is null or not.

decimal estRevBase = ((Money)cloudent["estimatedvalue"]).Value;
string des = estRevBase.ToString(); 
if (!string.IsNullOrEmpty(des))
    {
      estRev = Convert.ToDecimal(des);
    }
    else
    {
     estRev = 0 ;
    }

Still no luck :(

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Error when retrieve an empty money data type

    Hi,

    Please try the following code.

    var estRevBase = (Money)cloudent["estimatedvalue"];
    if(estRevBase !=null)
    {
       decimal estRevBaseValue = estRevBase.Value;
    } 

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error when retrieve an empty money data type

    Thanks

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error when retrieve an empty money data type
    Please use a check before assigning values :

    if (cloudent.Attributes.Contains("estimatedvalue")){
    decimal estRevBase = ((Money)cloudent["estimatedvalue"]).Value;
    }
    

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans