Length cannot be less than zero

Hi Team

im getting below error, local panel shows there is Input value(170200192577)but bot is not able to do typeinto, as throws with error.Can you please let me know resolution.

Type Into ‘INPUT Search PO Number’: Length cannot be less than zero.
Parameter name: length

Hi @Sikander_siki

Can you please let us know are you performing any kind of string operation while Typing.


Hi Suraj
Yes.bot picks up value from given index.

Can you try printing purchase order?

Please use an assign activity and make all the string operation and assign it to a Variable and pass the variable to the Type Into Activity.

Please make sure the Variables contains value.


Purchase order is getting printed ,but still throws with same error

You have a substring on it and I suspect some sort of calculation that’s resulting in a substring length of less than 0.

You’re doing nested Ifs. Honestly that’s poor coding. Use Else If. Much cleaner. Or use a Switch since it looks like all you’re doing is checking the value of DocType.

If all you’re doing is typing in a different value depending upon DocType, create a local variable and use a Switch to populate it with the value to type in, and then you don’t even need to have multiple Type Into activities.

Hi Suraj

Arguments are already passed ,when we invoke workflow to main.xaml then this error shows.

can you show the full expression that you have in the ‘type into’ field?

here is the expression
in_PurchaseOrder.Substring(0,in_PurchaseOrder.IndexOf(" ERS"))

The Substring method takes 2 arguments - Start Index and Length. In your case Length is -1 because IndexOf returns -1 if the string you are looking for (" ERS") is not found in the source string (in_PurchaseOrder). This is why you get the error - Length cannot be -1.

You need to add some logic to handle situations where " ERS" is not present in in_PurchaseOrder

Best first clean in_PurchaseOrder from any unwanted characters/strings and assign the result to a new variable. Then use that cleaned variable in Type Into

1 Like