Solved

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

Posted on 2016-09-20
8
32 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:hbash
  • 4
  • 4
8 Comments
 
LVL 42

Expert Comment

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

Author Comment

by:hbash
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 42

Expert Comment

by:zephyr_hex
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
 
LVL 1

Author Comment

by:hbash
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 42

Accepted Solution

by:
zephyr_hex earned 500 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:hbash
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 42

Expert Comment

by:zephyr_hex
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:hbash
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now