1

I am using a custom JS (which is borrowed) to show repeated section as in a more readable format, which does work fine. However, when using the search field then it throws an XML Invalid error...

TypeError: Unable to set property 'innerHTML' of undefined or null reference
TypeError: Unable to set property 'innerHTML' of undefined or null referenceTypeError: Unable to get property '_events' of undefined or null reference

When removing the below JS script then the search results works fine.
Can you please suggest what to try out ...

<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>  

<script type="text/javascript">  
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({  
  Templates: {  
           Fields: {  
                 //The Inventory refers to the column name 
                'FreightInventory': {   
                    'View': repeatingSectionViewTemplate  
                 }  
           }  
  }  
});  

function repeatingSectionViewTemplate(ctx) { 
//The Inventory refers to the column name  
   var xml = ctx.CurrentItem["FreightInventory"];  
   var decodedxml = xml.DecodeXMLNotation();   
   var htm = "";  

   xmlDoc = $.parseXML( decodedxml );  
   $xml = $( xmlDoc );  
   $xml.find("Item").each(function() {  
      htm = htm + "<tr><td width=90px>" + $(this).find("PartNumber").text() + "</td><td width=160px>" + $(this).find("PartDescription").text() + "</td><td width=35px>" + $(this).find("PartQuantity").text() + "</td><td width=160px>" + $(this).find("PartLine").text() + "</td><td width=160px>" + $(this).find("PartSupplierCustomer").text() +"</td></tr>";  
   });  

   return "<table border='0' width='600'>" + htm +"</table>";  
};  

//Replaces html notation to their equivalent xml escape characters.  
String.prototype.DecodeXMLNotation = function () {  
    var output = this;  
    if ($.trim(output) != "") {  
        output = output.replace(/&apos;/g, "'").replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&');  
    }  
    else {  
        output = "";  
    }  
    return output;  
};  

</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.