How to set a variable with default value based on the another variable in the catalog form

gharitha
Tera Contributor

I am trying to auto populate 3 single line text variables(RAM,CPU,Storage) with default values based on another variable "Server type"(type-choice) on the catalog form.Client script is not working for it.Don't know how to implement through macros.

Please let me know if you have any further questions.

Thank you for your help.

8 REPLIES 8

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


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



            g_form.setValue('CPU',"");


            g_form.setValue('RAM',"");


            g_form.setValue('storage',"");


        }


else if(newValue=='Small VM'){


                    g_from.setValue('RAM',"4");


            g_from.setValue('CPU',"2");


                    g_from.setValue('storage',"150");  


            }


else if(newValue=='Medium VM')


              {


            g_from.setValue('RAM',"8");


                    g_from.setValue('CPU',"4");


        g_from.setValue('storage',"300");


                      }



else if(newValue=='Large VM'){


            g_from.setValue('RAM',"16");


            g_from.setValue('CPU',"8");


            g_from.setValue('storage',"600");


             


      }


else if(newValue=='X-Large VM'){


            g_from.setValue('RAM',"32");


            g_from.setValue('CPU',"16");


            g_from.setValue('storage',"800");


             


      }


           


    //Type appropriate comment here, and begin script below


return;  


}


did you make sure that you are setting database names of fields but not labels/display value.


Yes,I am sure.Those all are database values only.


Try in this way! if this works




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


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



            g_form.setValue('CPU',"");


            g_form.setValue('RAM',"");


            g_form.setValue('storage',"");


        }



var servertypevalue = g_form.getValue('Server type'); // OR give whatever database name it is


if(servertypevalue =='Small VM'){


                    g_from.setValue('RAM',"4");


            g_from.setValue('CPU',"2");


                    g_from.setValue('storage',"150");


            }


else if(servertypevalue =='Medium VM')


              {


            g_from.setValue('RAM',"8");


                    g_from.setValue('CPU',"4");


        g_from.setValue('storage',"300");


                      }



else if(servertypevalue =='Large VM'){


            g_from.setValue('RAM',"16");


            g_from.setValue('CPU',"8");


            g_from.setValue('storage',"600");


           


      }


else if(servertypevalue =='X-Large VM'){


            g_from.setValue('RAM',"32");


            g_from.setValue('CPU',"16");


            g_from.setValue('storage',"800");


           


      }


         


    //Type appropriate comment here, and begin script below


return;


}