If statement not working with OR function in condition

Hi,

Hope someone can help. I’ve built an If Statement up that looks for a condition agaisnt variable called CustomerID and the condition is whether CustomerID=“MA14” Or CustomerID=“CAREC001”

Now when I run the process it runs the Else condition even though i’ve checked the Get Text Variable by pushing it out through a Message Box and it comes back with MA14. one of the 2 conditions.

Could someone help point me in the right direction with this as i’m sure its a fairly simple mistake i’m making but I cannot fathom what.

Thanks

Hi JayBee,

Try to Trim CustomerID variable before comparing.

Hi @JayBee

Try as below :-

CustomerID.ToString.Trim.Equals("MA14") Or CustomerID.ToString.Trim.Equals("CAREC001")

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi Both,

just tried using your solutions above but its still going through the Else clause, even when the Get Text Variable is definitely one of the two conditions.

any ideas what may be the issue?

Thank you.

Try “Contains” in place of Equals,

Or else write this GetText result in notepad and check whether newline is coming or not, maybe thats why it is happening.

I’ve just tried with ‘Contains’ same result.

So I’ve written the GetText result to notepad and this is the result below.

test.txt (4 Bytes)

Any thoughts?

Thank you for your help everyone.

Just a thought, but try deleting the if statement and manually creating again. I have seen some issues before on this.

I think there is/are some non ASCII character(s) getting picked up by the extraction logic. Can you please try

CustomerID = Regex.Replace(CustomerID , @"[^\u0020-\u007E]", string.Empty);

before checking it in the IF condition.

I’ve tried assigning to CustomerID with what you suggested but i get the following error.

any ideas?

Thank you.

Can you try: CustomerID.Any(function(x) x.ToString.Contains(“MA14”))
If that doesn’t work summon @Yoichi, he’s good with this stuff

Hi @JayBee ,

I suppose there are 2 possibilities of the cause. Can you try the following?

  1. Check if there is an argument which name is same as variable.
    If there is, can you remove it?

  2. Check result of the following expression before IF activity.

    String.Join(",",customerID.toString.Select(function(c) AscW(c).toString))

img20200811-2

If your string data is exactly “MA14”, the result will be 77,65,49,52. If there is other character, you need to handle it, for example, as @Madeshwaran_Mohanraj mentioned. As his expression is for C#, probably you need to write as the following.

CustomerID = System.Text.RegularExpressions.Regex.Replace(CustomerID , "[^\u0020-\u007E]", string.Empty)

Regards,

1 Like