roco Posted January 16, 2009 Share Posted January 16, 2009 Hello - I am hoping to get some help with the syntax for my javascript. I am using this to evaluate a series of rows and to create a variable called "qty" that is dependent on "sku" containing "PNV" at the beginning of the string(sample values are PNV676, PNV897987, XYT9878, VGG897987). If "sku" does start with "PNV" I need to add 10 to the already defined variable "On_Hnd" in "qty". If it does not start with "PNV" then just use the same value that is in "On_Hnd" for "qty".//Script herevar qty;var regex=/PNV/;var a = trim(sku.getString())if (a = regex) { qty = On_Hnd.getString()+10;} else { qty = On_Hnd.getString();}Unfortunately this does not give me a result, and I am sure it is because of the syntax as I am no expert here. Any help you could offer would be appreaciated. Thanks - roco Link to comment Share on other sites More sharing options...
Synook Posted January 16, 2009 Share Posted January 16, 2009 You need to use String.match(), not just test for equality (you have the wrong operator for equality anyway). Also, use the ^ character to specify the start of string in your regex. var qty;var regex=/^PNV/;var a = trim(sku.getString())if (a.match(regex)) qty = On_Hnd.getString()+10;else qty = On_Hnd.getString(); Also, make sure the classes that sku and On_Hnd are instances of have getString() as a method! Link to comment Share on other sites More sharing options...
roco Posted January 16, 2009 Author Share Posted January 16, 2009 You need to use String.match(), not just test for equality (you have the wrong operator for equality anyway). Also, use the ^ character to specify the start of string in your regex.var qty;var regex=/^PNV/;var a = trim(sku.getString())if (a.match(regex)) qty = On_Hnd.getString()+10;else qty = On_Hnd.getString(); Also, make sure the classes that sku and On_Hnd are instances of have getString() as a method! Hey this is great! This works much better. Thanks. I still have one issue with it though and that is that my qty field is not adding the numbers but rather concatenating strings. How do I get qty = the value of "On_Hnd" +10 ...........it must be another operater besides GetString? Link to comment Share on other sites More sharing options...
jeffman Posted January 16, 2009 Share Posted January 16, 2009 Correct way: qty = Number(On_Hnd.getString() ) + 10;Easy way: qty = 1 * On_Hnd.getString() + 10; Link to comment Share on other sites More sharing options...
Synook Posted January 17, 2009 Share Posted January 17, 2009 There is no such thing as getString() unless you define it, btw. Link to comment Share on other sites More sharing options...
roco Posted January 17, 2009 Author Share Posted January 17, 2009 SOLVED:Thank you all. I am using a program called Pentaho Data PDI and in it getString must be defined, because it works perfectly. Thank you all for your help. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.