Level 1
Level 2
Melden Sie sich an, um alle Badges zu sehen
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
Gelöst! Gehe zu Lösung.
Anhand von Themen werden Community-Inhalte kategorisiert und Sie können so relevanten Inhalt besser finden.
Zugriffe
Antworten
Likes gesamt
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
Zugriffe
Antworten
Likes gesamt
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?
Zugriffe
Antworten
Likes gesamt
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
Zugriffe
Antworten
Likes gesamt
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.
Zugriffe
Antworten
Likes gesamt
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
Zugriffe
Antworten
Likes gesamt
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.
Zugriffe
Antworten
Likes gesamt
@Marcel_Szimonisz parseInt worked for me. Thanks a lot for the help.
Zugriffe
Antworten
Likes gesamt
@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"
Zugriffe
Antworten
Likes gesamt
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.
Zugriffe
Antworten
Likes gesamt
Zugriffe
Likes
Antworten
Zugriffe
Likes
Antworten