Hi,
I am trying to use "if" condition to compare values of 2 variables that I am getting from SOAP call.
<% if(rtEvent.ctx.Consumer.oldid==rtEvent.ctx.Consumer.newid) { %>here<% } else { %>there<% } %>
I have checked in RT instance and found that value of "oldid" and "newid" are same but it is still going in "else" condition.
Can anyone please tell me what is wrong?
I have used "if" condition in the past but just to check variables's value against static value and this has worked.
e.g. <% if(rtEvent.ctx.Consumer.oldid=="correct") { %>here<% } else { %>there<% } %>
Thanks,
Vinay
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hello @vinay16 .
is it string or integer values? I usually cast these ctx values to respective string or integer when comparing. I have problems especially with numbers when tried to do rtEvent.ctx.var>10 the rtEvent.ctx.var is typeof xml can you try cast it? However I never had problems comparing other types than numbers.
rtEvent.ctx.Consumer.oldid.toString()//if string
parseInt(rtEvent.ctx.Consumer.oldid)//if number
if (rtEvent.ctx.Consumer.oldid.toString()==rtEvent.ctx.Consumer.newid.toString()){
//do something
}
Marcel
Views
Replies
Total Likes
There isn't any spelling mistake.
For values, I have checked in AC - Data and I can see same values are there. Don't know what is wrong. Can you please share insight?
Views
Replies
Total Likes
Hi @vinay16
Could you try storing the values in some variable and then putting them into comparison, I too face this issue sometimes for by this method it works fine for me. Don't know the exact reason but guess the dot method for location of a variable has some bug as it sometimes start reading it as a function.
Eg. var A = rtEvent.ctx.Consumer.newid;
var B = rtEvent.ctx.Consumer.oldid;
if (A==B) or if (rtEvent.ctx.Consumer.oldid==B)
{
do this;
}
Regards
Akshay
Views
Replies
Total Likes
Thanks for the reply.
I have tried
var A = rtEvent.ctx.Consumer.newid;
var B = rtEvent.ctx.Consumer.oldid;
if (A==B)
But it didn't work.
I will try to use second option.
Views
Replies
Total Likes
Update:
even second approach didn't work.
I have also tried to use
if(A!=B) and if(rtEvent.ctx.Consumer.newid!=rtEvent.ctx.Consumer.oldid)
Didn't work
Views
Replies
Total Likes
Hello @vinay16 .
is it string or integer values? I usually cast these ctx values to respective string or integer when comparing. I have problems especially with numbers when tried to do rtEvent.ctx.var>10 the rtEvent.ctx.var is typeof xml can you try cast it? However I never had problems comparing other types than numbers.
rtEvent.ctx.Consumer.oldid.toString()//if string
parseInt(rtEvent.ctx.Consumer.oldid)//if number
if (rtEvent.ctx.Consumer.oldid.toString()==rtEvent.ctx.Consumer.newid.toString()){
//do something
}
Marcel
These are integer values. Just numbers. Let me try parseInt for this and let you know.
Views
Replies
Total Likes
@Marcel_Szimonisz parseInt worked for me. Thanks a lot for the help.
Views
Replies
Total Likes
@Marcel_Szimonisz
I have one more question related to variable part.
If I am getting a feed and I need to check whether the variable exist in that feed or not, is there any way to do that?
As an example,
I'm getting SOAP call,
<ctx>
<Consumer>
<group>true</group>
<winner_original_drawdate>2023-09-29</winner_original_drawdate>
</Consumer>
</ctx>
Now for some instance, <winner_original_drawdate> won't be there any feed. so is there anyway to check in HTML part whether it exists or not
I want to display "A" if that variable exists and if not, I want to display "B"
Views
Replies
Total Likes
Hello @vinay16
usually you use hasOwnProperty but I do not recal if I have used it with ctx variables
can you try:
if (ctx.hasOwnProperty('winner_original_drawdate'))
Marcel
Thanks for suggestion.
I have used rtEvent.ctx.Consumer.winner_original_drawdate!=undefined and it worked for me.
Views
Replies
Total Likes