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

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

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

  • Comments 10
  • Likes

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';
}

 

Comments
  • Hi - I have a similar query. CRM 7.0d.

    In Cases, how do I make the case_status field change to Waiting when I change the Assigned User field?

    For example, all new Cases are assigned to System Admin, status = Pending. When Assigned User is changed ( to Damian Walsh for example), the case_status field value is automatically changed to Waiting

    Thanks in advance

    Bryano.

  • Assuming workflow is off for cases, you should be able to add case_status.value = 'Waiting' to the onChange Script. If Workflow is on, then you could add a new rule and state to accomplish this.

  • Hi, Jeff.

    I am new to Sage and OnChange scripting, etc. I used a variation of the scripting you have here to reflect my situation.

    switch (this.value) {

    case 'Introduction' :

    oppo_certainty.value = '5';

    break;

    case 'Presentation' :

    oppo_certainty.value = '25';

    break;

    case 'Quoted/Bid' :

    oppo_certainty.value = '50';

    break;

    case 'Negotiated' :

    oppo_certainty.value = '75';

    break;

    case 'Sold Open' :

    oppo_certainty.value = '90';

    break;

    case 'Sold Closed' :

    oppo_certainty.value = '100';

    break;

    I am looking to update the oppo_certainty when a value in the selection list for oppo_stage is chosen. (The stage is required, and to make it easy for the team, we want to update automatically.)

    I am putting it in the OnChange box and nothing is happening.

    Any wisdom on how I can fix this?

    Thanks!

  • Debbie

    You need to think about where those field exist, and how they are updated.  The oppo_stage and oppo_certainty field in a default system are found in the opportunitystatus box but and this is a big but.... the fields are written to the screen by a workflow rule.  So if you want to change these fields together are they being managed by workflow?  Or are you just working with the Opportunity Progress screens.

  • Thank you. It looks like three stages are showing as part of workflow. I guess this is my baptism through fire. :-/

  • Hi, Jeff.

    Me again. :-)

    We do not have workflow set as on for Opportunities so, in theory, there should not be a conflict, correct? I have tried multiple ways to get the certainty to update after the stage is changed but to no avail. I think the only way to address this at this point is a table script and I will honestly say ... that is currently above my pay grade. :-/ Or, do you think the OnChange can be tweaked to actually work?  Thanks and have a great day!

  • Debbie

    I've got a little lost in this thread.  Would you mind please posting the question in one of the forums and outlining the specific need that you have within the opening post?  Please provide as much information as you can.

    Thanks

  • Jeff, I just saw this ... I will. :-)

  • I have a got an almost similar scenario where I would like to change a team automatically based on a selected user.

    Background: There is a customized entity with a user select field and a team select field. Half of the time the user logged in uses the user select field to assign a contract to another user. Would it be possible to have the team field change automatically instead of having the user select the team the user belongs to?

    Your Assistance is highly appreciated.

  • 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;

    }