Set a default Currency Lookup Value on a Form

There are several forms in CRM that required a Currency value.  Today I created a new custom entity that has several currency attributes.  Since the user did not like adding the Currency value to the form each time he or she created a new record, I used some javascript on the Form OnLoad event to set the default currency for the form.  Users can always change the value if needed.  Below is the script with instructions for reference.  This is very easy to implement.
 
The first thing you need to do is obtain the guid for the Currency Value that you want to use in the Onload event.  Following is one way to obtain the value.
 
  • Open CRM and go to Settings, Business Management, Currencies
  • Open the currency record and select F11 or Cntrl N to view the IE address field if you don’t already have it displayed
  • Find the ID contained between the two brackets {}, copy the full value with bracktes and save it for use in the script

Next we’ll open the entity that we want to set with a default currency value.

  • Go to Settings, Customization, Customize Entities and open the entity that you want to set the default currency
  • Select Forms and Views from the left navigation menu
  • Select Form properties from the right "Common Tasks" menu
  • Select OnLoad and select Edit
  • Copy and paste the script below into the ‘script area’ and check the Event Enabled selection
    • Be sure to copy your Currency Guid into the appropriate place in the script
    • Select the Dependencies Tab and move the Currency field to ‘Dependent Fields" list
      • This will ensure that the field remains on the form
      • Save, close and test your changes

You can publish your changes when you are satisfied with the result.  I obtained the code below from a CRM post responded to by uMar Khan.  Thanks uMar, for the assist!

    if (crmForm.FormType == 1)

    {

    //Create an array to set as the DataValue for the lookup control.
    var lookupData = new Array();

    //Create an Object add to the array.
    var lookupItem= new Object();

    //Set the id, typename, and name properties to the object.
    lookupItem.id = ‘{CopyYourCurrencyGuidHere}’;
    lookupItem.typename = ‘transactioncurrency’;
    lookupItem.name = ‘US Dollar’;

    // Add the object to the array.
    lookupData[0] = lookupItem;

    // Set the value of the lookup field to the value of the array.
    crmForm.all.transactioncurrencyid.DataValue = lookupData;
    }

2 thoughts on “Set a default Currency Lookup Value on a Form

  1. below script i have used in CRM 2011

    function setdefaultcurrency()
    {
    var value = new Array();
    value[0] = new Object();
    value[0].id = “2ADA7F39-A910-E311-A612-00155D00EE04”
    value[0].name = “Svenska kronor”;
    value[0].entityType =”transactioncurrency”;
    Xrm.Page.getAttribute(“new_currency”).setValue(value);
    }

  2. i have use the below script in CRM 2011

    function setdefaultcurrency()
    {
    var value = new Array();
    value[0] = new Object();
    value[0].id = “2ADA7F39-A910-E311-A612-00155D00EE04”
    value[0].name = “Svenska kronor”;
    value[0].entityType =”transactioncurrency”;
    Xrm.Page.getAttribute(“new_currency”).setValue(value);
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s