Thursday, September 3, 2009

Scripting (Update Currency Symbols) - MSCRM 4.0


Recently we had a scneario wherein the currency field on the opportunity was to be set dynamically with the currency of the associated contact/account.
This currency is automatically set to the currency of the account/contact if the opportunity has been opened from within an account/contact, however it does not reflect the associated currency when the customer is changed.

So had to make an ajax call on the onchange event of the customer field to retrieve its associated currency and set it on the opportunity entity.
However this does not change the currency symbol values on the money fields on the form.
There seems to be an internal script being fired to update the currency symbols  whenever the currency is changed.
The same is not fired when the currency value is populated via javascript.

Below is the javascript which can be used to update the symbols whenever the currency is set dynamically:

//loops thru all controls on the form and sets the currency symbol
var oCtrl;
for (var i = 0; i < crmForm.all.length; i++)
{
      oCtrl = crmForm.all[i];
      if(oCtrl.tagName == "INPUT" && oCtrl.className == "ms-crm-Money-CurrencySymbol")
      {   
        //currencySymbol contains the actual symbol                             

        oCtrl.value = currencySymbol;  
      }                                                         
}

Search a text within a Trigger


Suppose you need to do a search for all triggers within a DB which has the text (say ‘delete from trn_cashflow’)

SELECT sysobjects.name AS [Object Name], text , * FROM
sysobjects, syscomments
WHERE
       sysobjects.id = syscomments.id
       and sysobjects.type in ('TR')
       and text like 'delete from trn_cashflow%'