Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

If logic not working

bryceh57660644
Level 2
Level 2

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-...

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);}
}

5 Replies
Manoj_Kumar_
Community Advisor
Community Advisor

@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_Kumar_
Community Advisor
Community Advisor

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

 

 

 

CedricRey
Level 5
Level 5
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
Employee
Employee

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!