Dynamics CRM error "A currency is required if a value exists in a money field" after converting Activity to Case - dynamics-crm

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.

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:
set default currency
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;
}
}
}

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.

set default currency in Personalize Workspace, General tab
NEW records will use this currency
For EXISTING records (before money field(s) added) use Advanced Find to find records with NO currency value, then use Bulk Edit to set currency

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

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.

Since this thread came up in my Google search when I was looking for a solution to this problem for CRM 2011, I thought I'd add my blog article explaining how to set the default currency lookup in the Onload of a CRM 2011 form using JavaScript, JSON and OData.
http://crmscape.blogspot.com/2011/03/crm-2011-set-default-transaction.html

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.

Fix for this problem
1. Add the base currency field also to the form.
2. Untick the "visible by default option" of the base currency field.

Related

VSTO: Get long-term EntryID from Microsoft.Office.Interop.Outlook.Folder query

I'm wondering if it's possible to get the long-term entry id from a Microsoft.Office.Interop.Outlook.Folder query. I can successfully query the table, but the entry id is always the short-term entry id. As I understand it, the short-term entry id has the potential to change from session to session.
Here's my example code that -- additionally -- gets the sender's address as well as the base columns:
Table table = folder.GetTable();
table.Columns.Add("SenderEmailAddress");
while (!table.EndOfTable)
{
Row row = table.GetNextRow();
string entryId = row["EntryID"].ToString();
string sender = row["SenderEmailAddress"].ToString();
...
}
Is it possible to add an additional column, allowing me to query the long-term entry id? Thank you.
Yes, you will need to request the PR_LONGTERM_ENTRYID_FROM_TABLE MAPI property. Since it is not one of the OOM properties, you will need to specify its DASL name - "http://schemas.microsoft.com/mapi/proptag/0x66700102":
table.Columns.Add("http://schemas.microsoft.com/mapi/proptag/0x66700102");
See Columns.Add on MSDN for more details.
You can open the item to get a long-term EntryID property value. Consider using the NameSpace.GetItemFromID method which returns a Microsoft Outlook item identified by the specified entry ID (if valid). Then you may retrieve the EntryID property value which should be a long-term EntryID.
Short-term entry identifiers are used primarily for rows in tables and entries in dialog boxes, whereas long-term entry identifiers are used for many objects such as messages, folders, and distribution lists.

Updating Transaction Currency On Form Doesn't Update Custom Money Currency Symbol

I'm creating an empty shell of a lead on a custom web page, then redirecting the user to the newly created lead. The TransactionCurrencyId on the lead is empty on load, and in the OnLoad event, JS is setting the TransactionCurrencyId, and then populating the custom Money field. Upon setting the money field, the following alert is being thrown:
A Currency is required if a value exists in a money field. Select a
currency and try again.
Manually clearing the TransactionCurrencyId, and then re-selecting the TransactionCurrency allows the user to manually populate the value.
Shouldn't the Transaction Currency be set by default, and how do I set the TransactionCurrencyId in order to set the Custom Money Currency Symbol?
I was able to get around this be calling this on the custom Money attribute in the onLoad, before actually setting the value:
att.$2_2.setCurrencySymbol("$")
Of course this is unsupported and not an ideal solution...

Determine new record in PreWriteRecord event handler and check value of joined field

There is custom field "Lock Flag" in Account BC, namely in S_ORG_EXT_X table. This field is made available in Opportunity BC using join to above table. The join specification is as follows: Opportunity.Account Id = Account.Id. Account Id is always populated when creating new opportunity. The requirement is that for newly created records in Opportunity BC if "Lock Flag" is equal to 'Y', then we should not allow to create the record and we should show custom error message.
My initial proposal was to use a Runtime Event that is calling Data Validation Manager business service where validation rule is evaluated and error message shown. Assuming that we have to decide whether to write record or not, the logic should be placed in PreWriteRecord event handler as long as WriteRecord have row already commited to database.
The main problem was how to determine if it is new record or updated one. We have WriteRecordNew and WriteRecordUpdated runtime events but they are fired after record is actually written so it doesn't prevent user from saving record. My next approach was to use eScript: write custom code in BusComp_PreWriteRecord server script and call BC's method IsNewRecordPending to determine if it is new record, then check the flag and show error message if needed.
But unfortunately I am faced with another problem. That joined field "Lock Flag" is not populated for newly created opportunity records. Remember we are talking about BC Opportunity and field is placed in S_ORG_EXT_X table. When we create new opportunity we pick account that it belongs to. So it reproduceable: OpportunityBC.GetFieldValue("Lock Flag") returns null for newly created record and returns correct value for the records that was saved previously. For newly created opportunities we have to re-query BC to see "Lock Flag" populated. I have found several documents including Oracle's recomendation to use PreDefaultValue property if we want to display joined field value immediately after record creation. The most suitable expression that I've found was Parent: BCName.FieldName but it is not the case, because active BO is Opportunity and Opportunity BC is the primary one.
Thanks for your patience if you read up to here and finally come my questions:
Is there any way to handle PreWrite event and determine if it is new record or not, without using eScript and BC.IsNewRecordPending method?
How to get value of joined field for newly created record especially in PreWriteRecord event handler?
It is Siebel 8.1
UPDATE: I have found an answer for the first part of my question. Now it seems so simple to me that I am wondering how I haven't done it initially. Here is the solution.
Create Runtime Event triggered on PreWriteRecord. Specify call to Data Validation Manager business service.
In DVM create a ruleset and a rule where condition is
NOT(BCHasRows("Opportunity", "Opportunity", "[Id]='"+[Id]+"'", "AllView"))
That's it. We are searching for record wth the same Row Id. If it is new record there should't be anything in database yet (remember that we are in PreWriteRecord handler) and function returns FALSE. If we are updating some row then we get TRUE. Reversing result with NOT we make DVM raise an error for new records.
As for second part of my question credits goes to #RanjithR who proposed to use PickMap to populate joined field (see below). I have checked that method and it works fine at least when you have appropriate PickMap.
We Siebel developers have used scripting to correctly determine if record is new. One non scripting way you could try is to use RuntimeEvents to set a profileattribute during the BusComp NewRecord event, then check that in the PreWrite event to see if the record is new. However, there is always a chance that user might undo a record, those scenarios are tricky.
Another option, try invokine the BC Method:IsNewRecordPending from RunTime event. I havent tried this.
For the second part of the query, I think you could easily solve your problem using a PickMap.
On Opportunity BC, when your pick Account, just add one more pickmap to pick the Locked flag from Account and set it to the corresponding field on Opportunity BC. When the user picks the Account, he will also pick the lock flag, and your script will work in PreWriteRecord.
May I suggest another solution, again, I haven't tried it.
When new records are created, the field ModificationNumber will be set to 0. Every time you modify it, the ModificationNumber will increment by 1.
Set a DataValidationManager ruleset, trigger it from PreSetFieldValue event of Account field on Opportunity BC. Check for the LockFlag = Y AND (ModificationNumber IS NULL OR ModificationNumber = 0)) and throw error. DVM should throw error when new records are created.
Again, best practices say don't use the ModNumbers. You could set a ProfileAttribute to signal NewRecord, then use that attribute in the DVM. But please remember to clear the value of ProfileAttribute in WriteRecord and UndoRecord.
Let us know how it went !

Current version of data in database has changed since user initiated update process

I have a Master Detail form in my Oracle APEX application. When I am trying to update data in this form, I am getting below error.
Current version of data in database has changed since user initiated
update process. current row version identifier =
"26D0923D8A5144D6F483C2B9815D07D3" application row version identifier
= "1749BCD159359424E1EE00AC1C3E3FCB" (Row 1)
I have cleared browser cache and try to update. But it not worked.
How can I solve this?
I have experienced similar problem where my detail records set has timestamp fields. By default master detail wizard creates the timestamp fields as date picker type fields. If you set the date format on these, it would resolve the issue.
This blog post tries to address this issue on a Tabular Form (I know that's not what the original issue was with, but thought it might be related). It says the same as #sangam does below.
Short version: If you have an updated field that's timestamp datatype, you should set a date/time format.
http://apexbyg.blogspot.com/2015/05/tabular-form-bug.html
My tabular form has a field that's timestamp datatype, but I had already set a date format, so this didn't help me.
Here's another possibility, which I discovered was the case in my application.
That would be if the data the original checksum was calculated on is truly different than the pre-update checksum calculation, due to a design-flaw in your query!
In my application, the source for one of the updateable fields was COALESCE(name_calced, name_preferred). In the source table, the person's name could already be loaded in the record by an external process and we save it to one field - name_calced. But the end-user can enter a preferred name, which we wanted to save to the name_preferred field. We wanted to initially populate the displayed, updateable tabular form field with name_calced, if one existed, or name_preferred if the user had already provided a preferred name. Then they could change that value and save it back to the database.
I finally discovered that the Save action threw the error message if name_calced was non-null, but name_preferred was null. I realized that the initial checksum was calculated based on name_calced, but the pre-update checksum was based on name_preferred, so the application thought someone had changed the value in the background and showed the error message.
What I don't understand is how this problem didn't show up in the past 3 years the application has been running in production!
My solution is to make the field source only on name_preferred, which immediately solved this problem. I also think the back-end process will also get changed to pre-populate that table field from name_calced, so the user always sees the base value, if there is one.
I just had this issue myself. Now, I realize that tabular forms are deprecated at this time, but I have an application that was developed beforehand and still uses them. This issue occurred and I had to get one of our big guns at Oracle to help me out. I do a lot of DB work and a decent amount of Apex development but I'm more of a Java, WebLogic, etc guy, and I really couldn't figure this one out.
In my case, it turned out to be really simple. One of the columns in my tabular form was a hidden field, generated via a sub query. Being hidden, this column is not editable by the user and should not be part of the MRU update. I had the field set to "Hidden Column (saves states)" and setting its type to "Hidden Column" fixed the issue. So, this leads to sub queries being executed in such a way as to change the checksum for the overall query before hitting submit (save), causing the error.
For those who are continuing to troubleshoot this, look at your query for every field that you have specified and note which columns are editable in the tabular form. All other fields should be set in a way that makes them not save state so that they are not part of the update.
I had this error when I had two update processes processing on submit.
My solution was to add a condition to both processing steps. I had forgotten to do this when I made an additional process for Button A, but I never updated Button B to limit it's behaviors.
Navigation:
Processing -> Processes -> [Your Process Name] -> Server-side Condition -> When Button Pressed = [Your button Name]
In my case I had a column from a secondary table that was not set as Query Only and was being updated! The error would occur trying to save a column not in the table being updated. It took me half a day to figure it out (the column names were the same).
Set your Link column hidden to display only in the form.
Set "Send On Page Submit" to 'No' or disable the link column that is your primary key ( Rownum/rowid/id etc).
Hope it will work for you.
I have noticed this error comes when I was working Tabular Form and has disabled one of the form operations i.e. by setting server-side condition to "Never" for add, apply changes (submit) buttons
When I have restored back to its original state, it worked as expected.
In case you have to hide Add/Update button, use some other option.
https://compknowledgebase.blogspot.com/2018/12/oracle-apex-error-current-version-of.html

How can I tell if an entity is disabled in Dynamics CRM 4.0?

In Microsoft Dynamics CRM 4.0, I want to be able to check if a record of any entity type is disabled. I think I can check the statecode. From the information I have seen, a value of zero means that the entity is enabled (editable in CRM) and any other value means disabled (for editing in CRM).
Is this assumption correct for all entities?
EDIT
If my assumption is correct, is it possible to create a QueryExpression for dynamic entities that does such a comparison, rather than using the text, "Active", which would be incorrect for quotes?
From what I've read, StateCode is not necessarily the same for every entity. It varies per entity.
I'm not aware of a way to disable an entity. I double checked our install, but don't see any option to disable. Google also yields no results to this end.
Do you mean perhaps individual entity records? If so, you'll have to check the StateCode for the entity you're looking at. I think most entities use StateCode as you describe, but for some entities, such as Activities, it seems to vary a little.
Here is some SQL I found to pull back the StateCode/StatusCode details of a particular entity:
select
AttributeName,
AttributeValue,
Value
from dbo.StringMap
where
(dbo.StringMap.AttributeName = 'statuscode'
or
dbo.StringMap.AttributeName = 'statecode')
and
dbo.StringMap.ObjectTypeCode = 1
ObjectTypeCode 1 maps to the Account entity.
Hope this helps.
EDIT: Just saw your addition. I think you'll be safe using StateCode in most instances. I personally use it in one of my projects to exclude disabled records on the Lead and Contact entities. Just double check the value mapping as I've described and then implement.

Resources