次の方法で共有


JScript Sample That Finds Blank Rows and Removes Them

I had a solution that aggregated multiple XML posts in a SharePoint Form Library into one document.   It was to consolidate multiple employee end of month reports into one big report.   The problem was that many of the areas of the InfoPath form that were supposed to be filled out weren't - for valid reasons - but there ended up being a bunch of blank lines in the final report.   I wanted to give the user of the final report a simple button to remove all the blank rows.   A guru of this stuff, Joel Alley, gave me the following code snippet:

 

Code to find rows that contain blanks and whack them.
function RemoveBlankRows::OnClick(eventObj)
{
   debugger;
   //Find any rows where the "TeamMemberName" attribute and the default text are empty
   var objBlankRows = XDocument.DOM.selectNodes(  "//*[(@my:TeamMemberName = \"\") and (.=\"\")]" );
  
   //Enumerate through each of the rows we found
   for (i=0; i< objBlankRows.length; i++)
   {
      //Remove the row from its parent node
      objBlankRows.item(i).parentNode.removeChild( objBlankRows.item(i) );
   }
}

 

Obviously you'd need to customize this to get full use out of it.   However, it does show you how to set a filter criteria that selects a group of nodes based on some criteria, and then how to loop through them and remove them from the XML.   I found this example very helpful.

Comments