If logic not working | Community
Skip to main content
bryceh57660644
Level 2
June 1, 2021
Question

If logic not working

  • June 1, 2021
  • 3 replies
  • 2587 views

Situation: I have created a 6 page micorsite for lead generation. The site has the ability to take in lead source variables that we pass through and I was looking to add in a backup as we have seen some gaps recently with this variable.  To fix the issue, I added in some JS to capture the tracking tag from a link and pass it through all the pages until they hit submit on the form. To do this I had to add in an if statement to only fill the variable if it is empty/null/undefined, but my logic isnt working and its repopulating on every page.  From what I can tell the IF itself isnt wrong, but when I search in the consol for the variable it doesnt appear, although it does in the AC debug mode. If the IF thinks the variableis empty, this would make sense why it is updating it constantly, but I cant figure out why its reading the variable that way. Any idea what I am doing wrong?

 

Site: https://www.sunlife.ca/ma//webApp/pma-index?WT.mc_id=en-us:direct:promo_email:provider_email:How-it-Works:05_27_2021

JS (fires onload):

function updateTrackingTag() {
var TrackingTag = document.controller.getValue('/ctx/vars/trackingtag');
if (TrackingTag !== "" || TrackingTag !== undefined || TrackingTag !== null) {
document.controller.setValue('/ctx/vars/trackingtag', TrackingTag);}
else {
document.controller.setValue('/ctx/vars/trackingtag', location.search);}
}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

_Manoj_Kumar_
Community Advisor
Community Advisor
June 1, 2021

@bryceh57660644 

 

Can you try changing your code to this one?.

function updateTrackingTag() { var TrackingTag = document.controller.getValue('/ctx/vars/trackingtag'); if (TrackingTag != "" || TrackingTag != undefined || TrackingTag != null) { document.controller.setValue('/ctx/vars/trackingtag', TrackingTag);} else { document.controller.setValue('/ctx/vars/trackingtag', location.search);} }

 

I am assuming it is not working because of data type issue.

 

Thanks,

Manoj

     Manoj     Find me on LinkedIn
bryceh57660644
Level 2
June 1, 2021
Same result unfortunately.
_Manoj_Kumar_
Community Advisor
Community Advisor
June 1, 2021

Hello @bryceh57660644 

 

follow these steps

  • Remove  // <![CDATA[  -> Available on the top of function 
  • Add a default value to trackingtag variable in web app properties. Lets says its 0
  • Then change if condition to  if(TrackingTag!='0')

Thanks,

Manoj

 

 

 

     Manoj     Find me on LinkedIn
CedricRey
Level 5
June 3, 2021
hello @bryceh57660644, Is the solution of Manoj ok for you ? I think this should work. When I go to your web site, I see you followed his recommandations, but there is a code problem (you declare a function 'saveTrackingTag' without the 'function' instruction and it throws an error).
Sukrity_Wadhwa
Community Manager
Community Manager
June 23, 2021

Hi @bryceh57660644,

Were you able to resolve this query with the given solution or do you still need more help here? Do let us know.

Thanks!

Sukrity Wadhwa