Avatar of Howard Bash
Howard Bash
Flag for United States of America asked on

Concatenated String Works on my SharePoint Online Site but Not on Another Site

I have built a JavaScript function which reads a JSON file and from that file it creates a string which represents the JSON array as a DIV structure.  This function works as expected on my Site,  but stops concatenating when run on another.  The JSON file is the same and so is the read and concatenation routine.

After about the 9th iteration through the array,  I examine the accumulating string in the debug tools console and even though the loop continues, the accumulating string stops acquiring additional substrings.

Is there some kind of resource limit that could be doing this in one site environment and not mine?
JavaScriptMicrosoft SharePointJSON

Avatar of undefined
Last Comment
Howard Bash

8/22/2022 - Mon
zephyr_hex (Megan)

can you please show us the code for how you're accumulating the string?
Howard Bash

ASKER
function BuildDiv(MyJSON) {
  var howMany=MyJSON.NavData.length;
  var out="";
  var iPtr=0;
  var itemData;
  var iTopCount=0;
  var rowCountInCurrentColumnDiv=0;
  var columnCountInCurrentSubMenu=0;
  var styleAttrib="";
  var DQ="\"";
  var itemDivOpen=false;
  var subMenuDivOpen=false;
  var colDivOpen=false;
  var MAX_ROWS_PER_COLUMN=3;
  
  var MENU_CONTAINER_DIV_TAB="\t";
  var ITEM_DIV_TAB="\t\t";
  var TOP_ANCHOR_TAB="\t\t\t";
  var SUB_MENU_DIV_TAB="\t\t\t\t";
  var COLUMN_DIV_TAB="\t\t\t\t\t";
  var COL_ANCHOR_TAB="\t\t\t\t\t\t";
  var CRLF="\n\r";
  
  var tgtAttribute="";
  
  //alert('Running BuildDiv');
    
  out = "<div class=" + DQ + "container" + DQ + ">" + CRLF;
  out += MENU_CONTAINER_DIV_TAB + "<div class=" + DQ + "menu-container" + DQ + ">" + CRLF;

  try {

  for (iPtr=0; iPtr<howMany; iPtr++)
    {
      itemData = MyJSON.NavData[iPtr];
	  tgtAttribute = itemData.target;
	  
      if (itemData.TopLevel=="1")
        {
           if (colDivOpen==true)
            {
              out+=COLUMN_DIV_TAB + "</div><!-- Close Column Div -->" + CRLF;
              colDivOpen=false;
            }
           if (subMenuDivOpen==true)
            {
              out+=SUB_MENU_DIV_TAB + "</div><!-- Close Sub Menu Div -->" + CRLF;
              subMenuDivOpen=false;
            }
           if (itemDivOpen==true)
		   {
			   out+=ITEM_DIV_TAB + "</div><!-- Close Item Div -->" + CRLF;			   
		   }
		   
		   //styleAttrib = " style=" + DQ + "float:left;padding:5px;height:auto;width:auto;padding-right:5px" + DQ;
		   styleAttrib = " style=" + DQ + "float:left;padding:5px 25px 5px 5px;height:auto;width:auto;" + DQ;
           iTopCount++;
           out+=ITEM_DIV_TAB + "<div class=" + DQ + "item" + DQ + ">" + CRLF;
		   itemDivOpen = true;
           out+=TOP_ANCHOR_TAB + "<a href=" + DQ + itemData.url + DQ + ">" + itemData.display + "</a>" + CRLF;
           out+=SUB_MENU_DIV_TAB + "<div class=" + DQ + "sub-menu" + DQ + ">" + CRLF;
           out+=COLUMN_DIV_TAB + "<div class=" + DQ + "col_" + 0 + DQ + styleAttrib + ">" + CRLF;
           itemDivOpen=true;
           subMenuDivOpen=true;
		   colDivOpen=true;
           rowCountInCurrentColumnDiv=0;  
           columnCountInCurrentSubMenu=0;		   
		}
		else
        {			
           if (subMenuDivOpen==true && itemDivOpen==true)
             {
				 if (rowCountInCurrentColumnDiv<MAX_ROWS_PER_COLUMN)
				 {
				   colDivOpen=true;
				   out+=COL_ANCHOR_TAB + "<a href=" + DQ + itemData.url + DQ + " target=" + DQ + tgtAttribute + DQ + ">" + itemData.display + "</a>" + CRLF;
				   rowCountInCurrentColumnDiv++;
				 }
				 else
				 {					 
				   out+=COLUMN_DIV_TAB + "</div><!-- Close Column Div -->" + CRLF;
				   rowCountInCurrentColumnDiv=0;      
				   columnCountInCurrentSubMenu++;				   
				   out+=COLUMN_DIV_TAB + "<div class=" + DQ + "col_" + columnCountInCurrentSubMenu + DQ + styleAttrib + ">" + CRLF;
				   out+=COL_ANCHOR_TAB + "<a href=" + DQ + itemData.url + DQ + " target=" + DQ + tgtAttribute + DQ + ">" + itemData.display + "</a>" + CRLF;
				   rowCountInCurrentColumnDiv++;
				 }					 
             }
        }				
    }

   if (subMenuDivOpen==true && itemDivOpen==true)
	 {
		out+=COLUMN_DIV_TAB + "</div><!-- Close Column Div -->" + CRLF;
		out+=SUB_MENU_DIV_TAB + "</div><!-- Close Sub Menu Div -->" + CRLF;
		out+=ITEM_DIV_TAB + "</div><!-- Close Item Div -->" + CRLF;
	 }		
	out+=MENU_CONTAINER_DIV_TAB + "</div><!-- Close menu-container div -->" + CRLF;
	out+="</div><!-- Close container div -->" + CRLF;
	 
    return (out);
  }
	
  catch (err) {
    alert (err.message);
  }
		
}

Open in new window

zephyr_hex (Megan)

There shouldn't be anything that prevents "out" from accumulating.  It's just a string.  My best guess is that one or more conditions are not being met.  To test this theory, you could put a matching "else" clause for every if statement and accumulate a test message to out in that condition.  For example, you check for this condition a couple of times, but don't specify what should happen when it isn't met:
if (subMenuDivOpen==true && itemDivOpen==true)
{
//..stuff you already have
}
else
{
  out+= "Oops, condition is false";
}

Open in new window

Or, if you have a debugger, you could put a breakpoint on when the if condition is not met (inside the else clause) and inspect to see why the condition wasn't met.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Howard Bash

ASKER
I put a breakpoint before the assignment.  I look at the value of out in the assignment.  I then go back to the debugged code and copy the substring that is about to be assigned to out and it is a full as expected value.

After I execute the out+= "some stuff" statement.  I go back to the console to view the out variable.  It has all the values up to part of the "some stuff" value.

Again, the odd thing to note is that this works fine on one Site Collection and fails on another.  Doesn't sound like code or data to me.
ASKER CERTIFIED SOLUTION
zephyr_hex (Megan)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Howard Bash

ASKER
Hi,

I discovered what it is and it has nothing to do with the sites and their configuration.  It's IE.  When I run the same javascript through Chrome,  I see the full string.  There must be a size limitation that IE developer tools will display.
zephyr_hex (Megan)

Well, that makes sense that it wasn't the code.

You should mark your answer as the solution to close out the question.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Howard Bash

ASKER
I will.  I just wanted to wait for you to read that and I will give you the solution as you were offering good faith suggestions.