Display Maximum Value Between 2 Fields

riaz_mansuri
Kilo Guru

Hi,

I am trying to create a script where the field displays the maximum value of 2 fields. So for example in Excel we would put in something like =MAX(D3:E3).

So in the below example Impact (Monetary) and Impact (Reputation) are both drop downs with a value of 1 - 5.

Impact max should display the maximum value (in the below case 5)

ImapctMax.JPG

Any help would be much appreciated.

Thanks

1 ACCEPTED SOLUTION

Hi Riaz,



Change the type onChange and select the field name as impact(reputation). Now paste the script as.


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '') {


  return;


  }


  var a =   g_form.getValue('u_impact_monetary');


  var b = g_form.getValue('u_impact_reputation');


  var c = Math.max(a, b);


  g_form.setValue('u_impact_max',c);


  //Type appropriate comment here, and begin script below



}


View solution in original post

9 REPLIES 9

Hi Pradeep,



Thank you, I am really not a "scripter" so you may have to tell me in a little detailed way.



So i added the below client script o the form:



var a =   g_form.getValue('current.u_impact_monetary');  


var b = g_form.getValue('current.u_impact_reputation');  


var c = Math.max(a, b);  


g_form.setValue('current.u_impact_max',c);  



What else do I need to change exactly? (Sorry but my scripting knowledge is not good at all I am a non technical person).



Thank you both for the very fast reply it is much appreciated.



Riaz



RiskValue2.JPG


Hi Riaz,



Change the type onChange and select the field name as impact(reputation). Now paste the script as.


function onChange(control, oldValue, newValue, isLoading, isTemplate) {


  if (isLoading || newValue == '') {


  return;


  }


  var a =   g_form.getValue('u_impact_monetary');


  var b = g_form.getValue('u_impact_reputation');


  var c = Math.max(a, b);


  g_form.setValue('u_impact_max',c);


  //Type appropriate comment here, and begin script below



}


Thank you both,



Almost I have been testing this and it certainty works.



The only thing is is that in order to get the max value in the Impact Max field a change has to be made to the Impact Reputation.



So for example if Impact Monetary can be set to 3 and Impact Reputation 4 that will = Impact Max to 4.



However if I change Impact Monetary to 5 now it will not change the Max value until Impact reputation is changed.



Any way of doing this so it recognises if either one is changed it picks the max value?



Many Many Thanks


Riaz


I think I would just duplicate the onChange script to watch both fields for changes and update the Max field when either one changes.


Thank you Both this works Perfectly



Fantastic... Thanks Pradeep and Kenneth very much appreciated



Riaz