I frequently hear from people looking for samples of javascript code for onchange events in CRM. Here's a sample we use in our internal CRM system for customer service cases.
We use cases to track all of our time, since all of our time should be spent working on something for a customer or working on an internal project. On our case forms we have a casetype picklist with the following values:
Maintenance Contract
Billable Services
Training
Sales
Admin/Overhead
If the case type is Maintenance Contract, we want to make sure the technician enters the contract that the case is related to. I use the following code in the casetype event box on the case customization form to set the contract field to "required" if the case is a Maintenance Contract case:
switch (parseInt(event.srcElement.returnValue, 6))
if (crmForm.casetypecode.returnValue != "1"){crmForm.SetFieldReqLevel("contractid",0);}
if (crmForm.casetypecode.returnValue == "1"){crmForm.SetFieldReqLevel("contractid",1);}
The first line basically says there are six choices in the picklist (the five listed options plus the default null option). Then the code says that if the selected option is not equal to option 1, then set the contractid to Not Required. The remainder of the code says that if the selection is equal to option 1, then set the contractid field to Required.
When setting up the form, set the contractid field to be Not Required by default. Note that you need the line of javascript that says "If selection is not equal to option 1, set the contractid field to Not Required." Even though this field is not required by default, you want to take into account the times when the end user sets the field to Option 1 (making the contractid field required) and then changes his mind, or realizes he made a mistake. In that case, you want to make sure the contractid field gets set back to being not required.
5 comments:
As far as I know, the only options available to the Javascript OnChange event are to make the field required or not required. CRM 1.2’s support for Javascript is pretty basic, unfortunately…
Hi,
I have a trouble, i don't now JavaScript very well, and i need make a customization, i need sum to fields, I guess program the script OnChange event of each textbox value. Could you show me some example of how to do this?
this are fields:
new_Total = estimatedvalue + valor2
thanks
Hi Matt,
Non Billable Hours
/----------------
How would you go about entering non billable hours for a case ? I see you have a case type of 'Admin/Overhead'. Do you alter or add scripting to run upon Resolving a case to skip allotment re-calculation based on this type.
Any suggestions or comments will be much appreciated.
Thanks
My event won't fire not even a Debugger; line will execute onchange
That code was for CRM 1.2. What version of CRM are you using?
Post a Comment