cancel
Showing results for 
Search instead for 
Did you mean: 

How to validate a value is float/double in a column-personas 2

0 Kudos

Hi everyone,

Anybody can give script for validate a value in the column is float or not.

If value is float, we have to stop the user from posting delivery.

Advance thanks to all.

Best Regards,

Dilak

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

To check if a number is an integer you'll need to use JavaScript. A Math function would work - something like Math.floor(x) == x. Or you could use a string test to look for non-zero characters after the point.

You'll also need to use Javascript to loop through the table as you can't do that in native Personas 2 scripting. Start with a Copy Table action - say that creates a copy called "table". The JavaScript would then look something like this:


qntcol = 6;     // Column number for the quantity field - check this!

rows = args.table[0].length;

po_list = new Array();

args.pass = "Y";

// Now validate all the quantities for(i = 0; i < rows; i++) {      qnt = args.table[qntcol][i];

     // The validation goes here

     if(Math.floor(qnt) != qnt) {

          args.pass = "N";

     }

}

After this, you will have a variable called "pass" you can check in the Personas v2 script. It will have the value "Y" if the test passed - i.e. all the values were integers - and "N" if not. You can enhance the JavaScript to also record which row failed, so that you can include that in any error messages - "Line 4 had a non-integer quantity".

Steve.

0 Kudos

Thank you Steve for your time;I applied your script;it's running without any errors;but var pass always return "N" even the quantity 1.000,2.000.Can you pls tell where I did anything wrong !

Could you please

Thanks and Regards

Dilak

Former Member
0 Kudos

My apologies - I didn't test that script before I posted it. I made three mistakes:

  1. I forgot how the columns were counted - I believe the quantities in your table are in column 4, not column 6
  2. Everything in the table will be of type string - before the "floor" function will work you need to use parseFloat to convert it to a number
  3. Row 0 of the table contains the column headings, so you need to process the rows from 1 onwards, not 0 onwards

Also, the line "po_list = new Array();" shouldn't be there. I started with a script designed to do something else as edited it for your scenario, and forgot to delete that line!

Taking all those things into account produces this:


qntcol = 4;     // Column number for the quantity field - check this!

rows = args.table[0].length;

args.pass = "Y";

for(i = 1; i < rows; i++) {     

     qnt = parseFloat(args.table[qntcol][i]);

     // The validation goes here

     if(Math.floor(qnt) != qnt) {

          args.pass = "N";

     }

}

I've tested this on a PO, testing for integer prices, and it works for me.

Steve.

Answers (0)