It's all about the answers!

Ask a question

Dojo Script for division || for Customized dicimal fileds


Lakshmi Narayana (2725) | asked May 04 '17, 7:17 a.m.

 Hi, I am able to use Dojo Script for addition and multiplication, but now sure how to do a division

 for e.g. I am using a script for addition  field1 + filed 2,  (10 +2=14)

but not able to do filed1/filed2 , ( 10/2=5). <o:p> </o:p>

 please suggest.

One answer



permanent link
Eduardo Bello (4401821) | answered May 04 '17, 10:02 a.m.
edited May 04 '17, 10:08 a.m.

 Hi,


  I tried a simple code here and the division works normally.

return workItem.getValue("test_num_1")/workItem.getValue("test_num_2");



 Try to use a try/catch to see if there is some exception... Like this:

        getValue: function(attribute, workItem, configuration) {
        try {
  var num1 = workItem.getValue("test_num_1");
var num2 = workItem.getValue("test_num_2");

var sum = 0;
if (!isNaN(num1) && !isNaN(num2)) {
  sum = num1/num2;
} else {
  sum = "";
}  
return sum;
} catch (err) {
            return err.message;
}
        }


 You might want to use the Number() method to force/parse the value into a Number value.

Your answer


Register or to post your answer.