Making a Field Appear Twice on a CRM Form

Paul Nieuwelaar, 30 June 2010

I was recently given the task of making a currency lookup field appear on two tabs at the same time, on the same form. After researching online for a way to make the same field appear twice on a form, I found a response to this question stating “It is not possible”. And they may have been right, but I kept looking anyway and found an alternative, which would make you think that it is the same field.

The first thing I did was create a new currency field, and make it look exactly like the original, even down to the Business Required star. I then positioned both lookups on the form where I wanted them, and added the following 1 line of code to each of the currency fields, ensuring Event is enabled for each one.

// Add this code to transactioncurrencyid’s onChange (the original field)
crmForm.all.new_currencyid.DataValue = crmForm.all.transactioncurrencyid.DataValue;

// Add this code to new_currencyid’s onchange (the field you just created)
crmForm.all.transactioncurrencyid.DataValue = crmForm.all.new_currencyid.DataValue;

Change the names in bold to the correct field names, where transactioncurrencyid is the name of the original field, and new_currencyid is the identical field you just created. It is important that the other field comes first in the code. For example adding: crmForm.all.new_currencyid.DataValue = crmForm.all.transactioncurrencyid.DataValue; to the new_currencyid fields onChange would be incorrect, and you would need to switch new_currencyid with transactioncurrencyid.

What this code does, it that when a value is entered into either of these two fields, the other field will be populated with exactly what was entered into the other field, and it works both ways so that they will always be updating the other field. This will make it appear that the field is in two places at once. If you ever needed to display the value of one of these fields in a view or find, you could just use the original field, since that will always be updated with the most current value.

The last thing to do, is to add one of those lines of code to the forms onLoad event, so that when the form is created, if the original currency field is prefilled, the custom field will also be prefilled.

It doesn’t matter which of the above lines of code you use in the onLoad event, so for example you could use:

crmForm.all.transactioncurrencyid.DataValue = crmForm.all.new_currencyid.DataValue;

You can use this method for any kind of field, not just lookups, so you could have two nvarchar, or money fields that have the same value. You can also have two fields that aren’t even the same type; but you can end up getting some strange results when you do this, so it pays to stick to related field types when doing this.