Hello everyone,
I need the syntax to use in an If activity to say: if in_TransactionItem equals 0, then delete the Excel sheet, given that in_TransactionItem is of type DataRow.
Thank you in advance.
Hi @Ben.Zineb
Please use the below condition
in_TransactionItem(“column name”).ToString = “0”
If the value is 0 → the Then section will run (where you delete the sheet).
Happy Automation !!
Hi @Ben.Zineb
A Datarow could consist of several columns depending on its origin.
Depending on what you want to check for, you could use:
If CInt(in_TransactionItem("ColumnName").ToString) = 0
Or perhaps if the argument is defined at all
If in_TransactionItem is Nothing
Regards
Soren
There can be many columns in datarow, first identify the column name, then only you can check if it zero.
Once you know the column name, replace in below expression it should work.
Convert.ToInt32(in_TransactionItem(“ColName”)) = 0
or
CInt(in_TransactionItem(“ColName”).ToString.Trim) = 0
You can also check if datarow is only empty like below
in_TransactionItem Is Nothing
Try this condition
in_TransactionItem IsNot Nothing AndAlso Convert.ToInt32(in_TransactionItem.Item("Jira").ToString) = 0
Hello Ben
Try:
CInt(in_TransactionItem.Item(“Jira”).ToString) = 0
Or
in_TransactionItem.Item(“Jira”).ToString = “0”
Cheers
Steve
The error occurs because you are trying to convert a text value (“RadioCanada”) to an integer using Convert.ToInt32, which causes the format exception.
Since in_TransactionItem(“Jira”) contains a string, you should not use numeric conversion. Instead, compare it as text:
in_TransactionItem(“Jira”).ToString.Trim = “0”
Or
String.IsNullOrEmpty(in_TransactionItem(“Jira”).ToString.Trim)
If the column may contain numbers sometimes, use a safe check with IsNumeric before converting. The issue is not with the If activity, it’s due to attempting to convert non-numeric text into an integer.
IsNumeric(in_TransactionItem(“Jira”).ToString.Trim) AndAlso
CInt(in_TransactionItem(“Jira”).ToString.Trim) = 0
If your queue is based on Excel (not Orchestrator) you should delete empty rows in your excel before process the queue. Then you will not need that if statement.
You could also check if the Column is numeric before trying to convert it to an integer:
I would go for something like this:
Not string.IsNullOrEmpty(in_TransactionItem(“Jira”).ToString.Trim) AndAlso IsNumeric(in_TransactionItem(“Jira”).ToString.Trim) AndAlso CInt(in_TransactionItem(“Jira”).ToString.Trim) = 0
If something else should happen if the value is empty or not numeric then you could use an ‘Else If’ ot handle each scenario seperatly
Hi @Ben.Zineb
As per screenshot, value coming in the txn item column is text and you are trying to compare it to 0 (integer value), that’s why the issue.
Queries:
- if JIRA would contain text values, why are you trying to equate it to 0? can 0 come in there? Do you mean to check if its null or empty? Please confirm whether 0 would be there for cases you are trying to handle or those would be empty?
Then basis on that, you can use your if condition..
if 0 can actually come, then try below:
if ((in_TransactionItem IsNot Nothing) And (NOT in_TransactionItem(“Jira”).ToString.Equals(“0”)))
and if it will be empty or null instead of 0, then try below:
if ((in_TransactionItem IsNot Nothing) And (String.IsNullOrEmpty(in_TransactionItem(“Jira”).ToString))
Hope this helps.
