views:

1581

answers:

5

We have a Dynamics CRM 4.0 instance with some custom attributes of type "money" on the Case entity and on all Activity entities (Email, Phone Call, etc.) When I use the built-in "Convert Activity to Case" functionality I find that the resulting Case does not have a Currency set, even if the Activity it was created from does have it. Whenever the case is opened the user then gets this JavaScript error:

A currency is required if a value exists in a money field. Select a currency and try again.

This is extremely annoying! How do I fix it? Is there any way I can set the currency? It needs to be done synchronously, because the Case is opened immediately when it's created from an Activity. So even if I started a workflow to set the currency the user would still get that error at least once. Alterntatively, can I just suppress the warning somehow? I don't really care about setting the Currency, I just want the error gone.

Thanks in advance for any help!

+1  A: 

You might want to check out this article CRM 4 Currency Calculations by Mitch Milam

Update : After googling around, i found out that you might need to set the transactioncurrencyid lookup somewhere. So in your case, it might be onsave or inside the execution of the workflow codes. I read it from here Error: Assign a decimal value to CRM 4.0 money field using Javascript

hadi teo
I don't have any workflow code - converting an activity to a case is built-in CRM functionality.
Evgeny
+1  A: 

If your form has a money field on it, CRM needs to know which currency to use. Verify that a default currency is set in your user preferences (Personalize Workplace from the main page, then the General tab). That is, each of your users will need to have a default currency set.

I have also been able to work around this issue by adding the currency field to the form, defaulting it to US dollars, and then hiding the field. If memory serves, though, this isn't ideal because the US dollars currency is a record in the system and can have different GUIDs in different environments.

Polshgiant
My default currency IS set. When you say "defaulting" the currency on the form - how do you do that?
Evgeny
Create a webservice that returns the lookup info of the US Currency record (or whichever currency you want your default to be). Then, add the transactioncurrencyid field to the form. On load of the form check to see if it is empty. If it is, call your webservice to get the lookup info of the default currency and use it to populate the field. Optionally, hide the field on the form.Certainly not a fun or quick workaround but it'll do the job.Did that answer your question?
Polshgiant
Do what Polsh says. I've done this with a few clients and this works great.
Matt
Thanks, I'll have to try this one out.
Evgeny
+1  A: 

I agree with Hadi Teo that you need to set the transactioncurrencyid. Its been awhile since I ran across this - so here is what I think I remember.

If you create a new entity with a money field populated the transaction currency will be set. If you update an entity, the transaction currency field will not be set.

I haven't used the Activity to Case function so I'm not all that sure what it does. One thing you can do as a work around is to add the transactioncurrencyid onto the form. Then you can set it before you modify your Case.

The other would be to default the currency in code. There are two places to determine the default currency. First off of the user settings. Second (if that is null) off of the organization settings.

benjynito
The Currency field is already on the Case form. Of course, the user can manually set it, but that's a hassle - and they still get the warning message at least once before they set it.I've set a default Currency in my user settings, but where do I go to set it for the Organization?
Evgeny
Its automatically set for the organization (I'm guessing by which version you install) when you install. Having the user setting populated won't automatically fill in the currency on an existing entity - only on a new entity. You're either going to need to add script or a create plugin to fill in this field yourself.
benjynito
+1  A: 

This annoying issue was resolved on my system by discovering the transactioncurrencyid used for US dollars and then updating the transactioncurrencyid column in the entity's database table for all the existing entity records. After doing this I was able to add money values on the entity form with no further problems. Not sure if this solution would be ideal for everyone, but as I did not want to write code to do this and felt I shouldn't have to since if I added money attributes to a newly defined entity it didn't require writing code on my part to populate the transactioncurrencyid field - it just did it by default. So in summary, this problem only seems to occur if the the money fields are added to an existing entity that has existing data associated with it.

mike
A: 

I guess this code will be helpful for next person who have a same problem. I spent whole day to figure out what I did below.

There are two steps involved here: 1) set default currency 2) set currency symbol for the money field.

Here is the code sample.

var currency = crmForm.all.transactioncurrencyid;

if (currency.DataValue == null) {
var lookupData = new Array(); var lookupItem= new Object();

//Get transaction currency value from : //select TransactionCurrencyId from MSCRM.dbo.TransactionCurrency
lookupItem.id = '{The GUID that you get from the SELECT statement above}'; lookupItem.typename = 'transactioncurrency';
lookupItem.name = 'US Dollar';

lookupData[0] = lookupItem;
currency.DataValue = lookupData;

//set default currency symbol for all the Money field. var defaultSymbol = '$'; for(var i=0; i < crmForm.all.length ; i++) { var oCtr = crmForm.all[i]; if(!IsNull(oCtr.IsMoney) && !oCtr.IsBaseCurrency) { oCtr.CurrencySymbol = defaultSymbol; } }

}

Jinho