Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-09-20
8
Medium Priority
?
48 Views
Last Modified: 2016-10-04
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?
0
Comment
Question by:Howard Bash
  • 4
  • 4
8 Comments
 
LVL 44

Expert Comment

by:zephyr_hex (Megan)
ID: 41807345
can you please show us the code for how you're accumulating the string?
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 41807450
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

0
 
LVL 44

Expert Comment

by:zephyr_hex (Megan)
ID: 41807494
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.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:Howard Bash
ID: 41807505
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.
0
 
LVL 44

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 total points
ID: 41827237
Honestly, I don't know how anyone can answer this.  It's a stab in the dark.

It would help if you posted example data showing an iteration that works, and an iteration that does not work.

Also, does it always stop concatenating in exactly the same place?  If so, try removing some lines from your file and test to see if / where it stops concatenating.

This is going to be a problem with something outside of the code you posted (such as file content -- even if the files are identical, NavData may be interpreting something differently).

Also, can you post the code for NavData?  Or is it some 3rd party tool?
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 41827317
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.
0
 
LVL 44

Expert Comment

by:zephyr_hex (Megan)
ID: 41828238
Well, that makes sense that it wasn't the code.

You should mark your answer as the solution to close out the question.
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 41828240
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.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question