var hostWebUrl;
var appWebUrl;
var appCtxSite;
hostWebUrl = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
appWebUrl = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'));
function manageQueryStringParameter(paramToRetrieve) {
// Geting Error here-Unable to get property 'split' of undefined or null reference
    var params =
    var strParams = "";
    for (var i = 0; i < params.length; i = i + 1) {
        var singleParam = params[i].split("=");
        if (singleParam[0] == paramToRetrieve) {
            return singleParam[1];
$(document).ready(function () {
    $(".BtnSumit").click(function () {

var listItem;
function Insert() {
    var ctx = new SP.ClientContext(appWebUrl);//Get the SharePoint Context object based upon the URL
    // var context = new SP.AppContextSite(ctx, hostWebUrl);
    // var web = context.get_web(); //Get the Site 
    var list = ctx.get_web().get_lists().getByTitle("List"); //Get the List based upon the Title
    var listCreationInformation = new SP.ListItemCreationInformation(); //Object for creating Item in the List
    listItem = list.addItem(listCreationInformation);
    listItem.set_item('StartDate', $("#txtSDate").val());
    listItem.set_item('EndDate', $("#txEDate").val());
    listItem.set_item('Purpose', $("#txtPurpose").val());
        Function.createDelegate(this, success),
        Function.createDelegate(this, fail)

function success() {
function fail() {
    alert("failed -- " + appWebUrl);
  • It seems you have blank value in string and you are trying to perform split operation. can you check what you get in document.URL.split("?")[1] ?
    – Ravindra
    Commented Aug 11, 2016 at 11:45

2 Answers 2


Everyone copies this code from blogs and it has a serious bug when there are no parameters.

And you do not need the code..

What does this code getQueryStringParameter do?


There are only three "splits" in your code - and the error says you're trying to split on "undefined or null". So either

  • document.URL is undefined (unlikely) or
  • document.URL.split("?")[1] is undefined (I'd guess this is it..) or
  • one of the params[i] is undefined

(However, personally I'd remove that code and go for the first answer!)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.