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)

Setting the value of Money-types using OrganizationService

(0) ShareShare
ReportReport
Posted on by

Hi all

I am trying to create an account in CRM 2015 using the OrganizationService from BizTalk. It almost works - I have issues getting values into fields that are of the "Money"-type. In order to test, I have created a small .NET application to simulate creating the XML BizTalk will be creating and in this small .NET application I cannot get values into Money-fields either.

My sample code is as this:

void CreateAccount()
{
    OrganizationServiceClient client = new OrganizationServiceClient();
    client.ClientCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

    Entity entity = new Entity() { LogicalName = "account" };
            
    AttributeCollection contactAttCollection = new AttributeCollection();
    contactAttCollection.Add(new KeyValuePair<string, object>("accountnumber", "98269828"));
    contactAttCollection.Add(new KeyValuePair<string, object>("creditlimit", 1000.00));
    contactAttCollection.Add(new KeyValuePair<string, object>("name", "Jan Eliasen Dummy Corp"));
            
    entity.Attributes = contactAttCollection;

    Guid g = client.Create(entity);
}


I do not get any exceptions, but the value for "creditlimit" is null in the AccountBase-table in the database, whereas other fields, such as name, telephone number and so on are added just fine. I have researched and found that I probably need to set a currency for the amount in order to let CRM know how to understand the amount. I have tried setting it in two ways:

contactAttCollection.Add(new KeyValuePair<string, object>("transactioncurrencyidname", "DKK"));
contactAttCollection.Add(new KeyValuePair<string, object>("transactioncurrencyid", new Guid("A9CFECC5-0970-E511-80CB-005056814687")));


where the guid-value is the one I found for the DKK-currency in the "TransactionCurrency"-table in the CRM-database.

Neither seem to work, as the value for TransactionCurrencyId stays null in the created row in the AccountBase-table.

I cannot use the SDK-classes and the Money-class because this is not supported by BizTalk - I need to create the XML for the OrganizationService my self.

Does anyone know how I can specify the currency? Or get Money-fields to work in another way?

Thanks!

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to change line

    contactAttCollection.Add(new KeyValuePair<string, object>("creditlimit", 1000.00));

    to line

    contactAttCollection.Add(new KeyValuePair<string, object>("creditlimit", new Money(Convert.ToDecimal(1000.00))));

  • Community Member Profile Picture
    on at

    Thanks for the very fast answer :-)

    I think the Money-class only takes in a Decimal in its constructor when you use the SDK-classes and not when you use a service-reference to the OrganizationService itself. I get a compile time error anyways :-)

    I tried modifying your code to this;

    contactAttCollection.Add(new KeyValuePair<string, object>("creditlimit", new Money() { Value = (Decimal)1000.00 }));


    but that gave me this exception:

    There was an error while trying to serialize parameter schemas.microsoft.com/.../Services:entity. The InnerException message was 'Type 'TestCRM.crmref.Money' with data contract name 'Money:schemas.microsoft.com/.../Contracts' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.


    the InnerException doesn't have any extra information.

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