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)

Set Currency field value

(0) ShareShare
ReportReport
Posted on by

i have a currency field, that needs to be filled through a plugin, this plugin calls a webservice, the webservice returns something like (USD, GBP,EUR,...) as a string, based on this returned value, i have to set the Currency 

any help would be appreciated 

thanks 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Hosk Profile Picture
    on at

    Currency field is an entityReference

    So you would need to use your string value to lookup the TransactionCurrency entity (currencies in your advanced find) to then get the guid of that currency.  Then when you have the currency you can create an EntityReference

    Example below taken from this blog

    stackoverflow.com/.../dynamics-crm-2011-setting-currency-field-programatically

    EntityReference currencyType = new EntityReference();

    currencyType.Id = "(The Guid Of The Currency Type Goes Here)";

    currencyType.LogicalName = "transactioncurrency";

    Then save the entityRefernce to the correct field on the record

  • Community Member Profile Picture
    on at

    Thanks Ben for the help,

    could you please guide me on how can i get the guid for (USD for example) in code ?

    i tried many possible ways but nothing worked

  • Verified answer
    Community Member Profile Picture
    on at

    i have solved this using the query expression like this :

    Entity entity = new Entity("transactioncurrency");

               Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)

                   serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));

               IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               QueryExpression query = new QueryExpression(entity.LogicalName);

               query.ColumnSet.AddColumns("transactioncurrencyid");

               query.Criteria = new FilterExpression();

               query.Criteria.AddCondition("isocurrencycode", ConditionOperator.Equal, shortName);

               EntityCollection results = service.RetrieveMultiple(query);

               if (results.Entities.Count == 0) return null;

               else

                   return (Guid)results.Entities[0].Attributes["transactioncurrencyid"];

     

     

    where shortName is my (string)currency code 

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