Page 1 of 1

Problems with If statement inside of foreach loop.

Posted: Thu Mar 17, 2016 6:47 pm
by john_a
I am somewhat confused as to why I cannot set a simple 'IF' statement in my foreach loop which is inside my convert to Xml.

Here is the perplexing bit -
This is acceptable syntax...
${varData[3]} eq ${varData[1]}

But when I try to use the 'ne' operator it is not acceptable syntax. In point of fact nothing but that actually is acceptable but that is not what I need to compare.

Here are some things I have tried and are all failing.

[8003 - Convert to XML] Invalid value '${varData[3]} ne ${varData[1]}' for attribute 'test' in element 'if'

[8003 - Convert to XML] Invalid value '${IsNotEmpty(varData[3])}' for attribute 'test' in element 'if'

[8003 - Convert to XML] Invalid value '${IsNotNull(${varData[3]})}' for attribute 'test' in element 'if'

[8003 - Convert to XML] Invalid value '${IsNotNull(varData[3])}' for attribute 'test' in element 'if'

Can someone tell me what is wrong with my syntax? What I would really like to do is this -
<if test="IsNotNull(${varData[3]})">

Re: Problems with If statement inside of foreach loop.

Posted: Thu Mar 17, 2016 7:02 pm
by Support_Rick
Change your statement from this:

${varData[3]} ne ${varData[1]}

To this:

${varData[3] ne varData[1]}

Then try it again...

Re: Problems with If statement inside of foreach loop.

Posted: Thu Mar 17, 2016 7:08 pm
by john_a
Actually what I really want to do is test varData[3] for null as I previously said and no that did not work and returns this error in "RED".

[8003 - Convert to XML] Invalid value '${varData[3] ne varData[1]}' for attribute 'test' in element 'if'

Re: Problems with If statement inside of foreach loop.

Posted: Tue Mar 22, 2016 1:19 pm
by Support_Rick
John,

My apologies, but I thought this was something else...

The XML Condition is literally if there are matching records in a rowset, not for conditional element display. This means that it's treated like a Header/Detail format... the condition is "if there's a matching detail to the header" not the option of something like "if this value is null".

So, to accommodate what you're looking for, it will have to happen in the SQL Select and/or by setting separate rowsets with associated values.

Hope this makes sense.

Re: Problems with If statement inside of foreach loop.

Posted: Tue Mar 22, 2016 1:20 pm
by john_a
I did find a solution to this and yes I see that the only conditional operators that are allowed are EQ and NE.

Re: Problems with If statement inside of foreach loop.

Posted: Fri Apr 15, 2016 1:14 pm
by Support_Tim
Hi John,
I know we found your answer last month, but just wanted to follow up here for others.

When comparison expressions are embedded within loop in a Write XML task, the ‘NE’ is not supported. As you have found, you need to use the ‘EQ’ instead and alter your logic accordingly.

Support for the ‘NE’ is being considered by development for new releases, but a release date or version has not yet been determined.