Using an onChange Script on a Selection list to set a value of another field

Less than one minute read time.

This is a simple real world example.

There was a customer need to set a field values based on value of another field on the opportunity screen. The screens had been customized. The oppo_forecast and oppo_certainty fields were removed from the opportunitystatusbox and oppo_certainty was added to the opportunitydetailbox screen along with a new field called oppo_forecastcategory. Oppo_forecastcategory was a Selection list. Its values were either 'None', 'A' 'B', 'C', 'D.

If the changes the drop down field Forecast Category to "˜B', the Certainty value needs to set to 40.

This can be expressed as an onChange rule

The code used was:

switch (this.value) {
case 'A' :
oppo_certainty.value = '20';
break;
case 'B' :
oppo_certainty.value = '40';
break;
case 'C' :
oppo_certainty.value = '60';
break;
case 'D' :
oppo_certainty.value = '80';
break;
default :
oppo_certainty.value = '5';
}

Parents
  • Stephen

    The easiest way to ensure that the oppo_channelid matches that of the oppo_assigneduserid if the oppo is reassigned is to set the value using a tablelevel script.

    Within an updaterecord() event function you can check the value of the new oppo_assigneduser when it is changed

    if(Values("oppo_assigneduserid")!=CRM.GetContextInfo("opportunity","oppo_assigneduserid"))

    {

    //the oppo has been reassigned;

    //find the user's record

    var UserRecord = CRM.FindRecord("user","user_userid="+ CRM.GetContextInfo("opportunity","oppo_assigneduserid"));

    //reset the team value

    Values("oppo_channelid") = UserRecord.user_primarychannelid;

    }

Comment
  • Stephen

    The easiest way to ensure that the oppo_channelid matches that of the oppo_assigneduserid if the oppo is reassigned is to set the value using a tablelevel script.

    Within an updaterecord() event function you can check the value of the new oppo_assigneduser when it is changed

    if(Values("oppo_assigneduserid")!=CRM.GetContextInfo("opportunity","oppo_assigneduserid"))

    {

    //the oppo has been reassigned;

    //find the user's record

    var UserRecord = CRM.FindRecord("user","user_userid="+ CRM.GetContextInfo("opportunity","oppo_assigneduserid"));

    //reset the team value

    Values("oppo_channelid") = UserRecord.user_primarychannelid;

    }

Children
No Data