Start a Conversation

Unsolved

This post is more than 5 years old

683

April 1st, 2015 17:00

if statement with OR

Hi,

I'm trying to get if statement to compare against mutiple strings in one statement but it is failing for some reason. (Verified the statement to be working seperately without using || )

deviceObj = object(eventObj->OccurredOn);

   if (!deviceObj->isNull()){

   if (deviceObj->PrimaryOwnerContact == "P2" || deviceObj->PrimaryOwnerContact == "P2test " ){

   eventObj->Severity = 2;

   eventObj->changed();

   }

although the following works fine

deviceObj = object(eventObj->OccurredOn);

   if (!deviceObj->isNull()){

   if (deviceObj->PrimaryOwnerContact == "P2" ){

   eventObj->Severity = 2;

   eventObj->changed();

   }

any suggestion?

170 Posts

April 2nd, 2015 01:00

Hi knakawa,

Your code looks good and I tested it in my environment just to double check and it worked as expected.

I believe the issue maybe that you have an extra space after P2test:

PrimaryOwnerContact == "P2test "

This is probably not matching the PrimaryOwnerContact value.

Can you please re-try the script as follows:

deviceObj = object(eventObj->OccurredOn); 

if (!deviceObj->isNull()){   if (deviceObj->PrimaryOwnerContact == "P2" || deviceObj->PrimaryOwnerContact == "P2test" ){ 

eventObj->Severity = 2; 

eventObj->changed(); 

}

Let me know how this goes. Thanks,

Kind Regards,

Paul O'Rourke

No Events found!

Top