2 Replies · Latest reply on Apr 28, 2017 6:08 AM by Michelle Kelly

    Suggestion on how to calculate CAPX 5 year view

      Hi all

       

      I have a requirement to auto calculate the CAPX 5 year view and display each year result in the fields yr1 to yr6 if expense type = CAPX.

       

      I have a on change client script currently in place to calculate the total cost. Not sure whats the best way to approach this requirement - After Business rule or onchange Client script.

       

       

      Currently this is calculated in excel and they manually inputted. Everything highlighted in blue is what needs to be entered and everything highlighted in yellow is a calc.

       

       

       

      All suggestion / help really appreciated.

        • Re: Suggestion on how to calculate CAPX 5 year view
          Julian Hoch

          Can you expand on this a little?

          What is the greater use case your trying to solve? Can you provide some context around your question? The form in the screenshot does not look familiar to me, are you customizing Asset Management or Financial Management to fulfil some specific requirements? If so, what are these?

            • Re: Suggestion on how to calculate CAPX 5 year view
              Michelle Kelly

              Hi Julian

               

              I was able to complete the above requirement by creating a reusable client script.

               

              function onLoad() {

                 //Type appropriate comment here, and begin script below

                

              }

               

              function calcCapx() {

               

                if ( g_form.getValue('u_expense_type') != 'CAPX' ) {

                resetYrVals();

                return;

                }

               

                var startdt = g_form.getValue('u_start_date');

                if ( startdt == '' ) {

                resetYrVals();

                return;

                }

               

                var totCost = g_form.getDecimalValue('u_total_cost');

                if ( totCost == 0 ) {

                resetYrVals();

                return;

                }

               

                yrlyVals = totCost / 5;

                g_form.setValue('u_year2', yrlyVals);

                g_form.setValue('u_year3', yrlyVals);

                g_form.setValue('u_year4', yrlyVals);

                g_form.setValue('u_year5', yrlyVals);

               

                var valMonth = Number(startdt.substring(5, 7));

               

                var remainingmonths = 12 - (valMonth - 1);

                var yr1 = (yrlyVals / 12) * remainingmonths;

                var yr6 = (yrlyVals / 12) * (12 - remainingmonths);

               

               

                g_form.setValue('u_year1', Math.round(yr1 * 100) / 100);

                g_form.setValue('u_year6', Math.round(yr6 * 100) / 100);

               

              }

              function resetYrVals() {

                g_form.setValue('u_year1', 0);

                g_form.setValue('u_year2', 0);

                g_form.setValue('u_year3', 0);

                g_form.setValue('u_year4', 0);

                g_form.setValue('u_year5', 0);

                g_form.setValue('u_year6', 0);

              }

               

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

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

                    return;

                 }

                 calcCapx();  

              }