Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Unable to get property 'toUpperCase' of undefined or null reference

$
0
0

I am trying to check if document exist or not in a document library and using the following JavaScript, I get the 'Unable to get property 'get current' of undefined or null reference' error in the debugger.

<script type="text/javascript">


        function ValidateFile() {
            var fupload = document.getElementById("<%= fuMSSFile.ClientID %>");

            var filename = fupload.value;
            if (filename != '') {
                var lastIndex = filename.lastIndexOf("\\");
                if (lastIndex >= 0) {
                    filename = filename.substring(lastIndex + 1);

                    var DocLibName = '<%=MSSDocLibName%>';
                    var fileURL = '/' + DocLibName + '/' + filename;


                    $(function () {

                        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getFileExists);

                    });

                    //ExecuteOrDelayUntilScriptLoaded(getFileExists, "sp.js");

                    getFileExists(fileURL,
                        function (fileFound) {
                            if (fileFound)
                            { ConfirmUpload() } else { document.getElementById('<%=HiddenField.ClientID%>').value = 'N'; };
                        },
                 function (error) {
                      console.log(args.get_message());
                                 alert(args.get_message())
                                });

                }
                else { document.getElementById('<%=lblMsg.ClientID%>').value = "Please select file to upload" }
            }
        }


        function getFileExists(fileUrl, complete, error) {

            var ctx = new SP.ClientContext.get_current();
            //var ctx = SP.ClientContext.get_current();
            var file = ctx.get_web().getFileByServerRelativeUrl(fileUrl);
            ctx.load(file);
            ctx.executeQueryAsync(function () {
                complete(true);
            },
            function (sender, args) {
                if (args.get_errorTypeName() === "System.IO.FileNotFoundException") {
                    complete(false);
                }
                else {
                    error(args);
                }
            });
        }</script>

          



The reading I've done seems to indicate that this is a problem with sp.js loading after the getItem() function is called.

So I added the following line:

ExecuteOrDelayUntilScriptLoaded(getItem, "sp.js") & SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getFileExists);

Which gets me a new error, this time in sp.js: "Unable to get property 'toUpperCase' of undefined or null reference."

I'm guessing that this is because the getItem () function is returning no data, but it's odd, because sp.js still seems to be loading afterwards -- that is,
I always get the 'get current' error first, then the 'toUpperCase' error.

Any suggestion



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>