Need help with a business rule to set a value in a field

kuarq
Mega Contributor

Hello,

I need to set a value in a field (decimal) depending on the selection of a choice list field. I suppose this can be done with a business rule but can't make it to work.

The choice list field is 'size' and the choices in the list have the following values: small, medium, large, xlarge and xxlarge

The field to set the value is 'score_size'

The logic is:

Condition:

If 'size' changes

Action:

If size = small then score_size = 2

If size = mediumthen score_size = 4

If size = large then score_size = 6

If size = xlarge then score_size = 9

If size = xxlargethen score_size = 10

I created a condition stating

Need some help with the code and is this gonna be a before or after rule?

Thank you

1 ACCEPTED SOLUTION

I managed to do it with an before business rule with the following code:



(function executeRule(current, previous /*null when async*/) {



current.score_size = current.size;



})(current, previous);


View solution in original post

5 REPLIES 5

vrfox
Giga Contributor

This would be a ui script... and with the onChange.. so if one field changes the other one will change a also


kuarq
Mega Contributor

Hello Carlo,



I think a UI script won't work in my case because I forgot to mention that the field 'score_size' receiving the value is a hidden field.


Dylan Mann1
Giga Guru

I believe you can use a client script and accomplish this without any code. Just set your condition to fit your needs.



If you want to use a business rule I think you would want it be before so the value changes and is then saved to the database. In your code set,  



score_size = '0';



this will change the value for you.



Cheers,



Dylan


It doesn't have to be '0' either! It can be whatever the number is for that particular choice, hope this helps.



Dylan