0

I am using variable from another method (AppPath) and trying to assign its value to title field. But this is not working. I am doing some basic mistake may be not declaring global variable( I have tried that also using google, if this is the case please provide me exact step to declare and where to declare). can someone please help. Below is my code

\

function createList()
 {   
    var clientContext = new SP.ClientContext(siteUrl);

    var oList = clientContext.get_web().get_lists().getByTitle('coolnew');

    var itemCreateInfo = new SP.ListItemCreationInformation();

    this.oListItem = oList.addItem(itemCreateInfo);
        alert('1');
    oListItem.set_item('Title', AppPath);
          alert('2');
    oListItem.update();

    clientContext.load(oListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
   }

 function onQuerySucceeded() {  
    var result = oList.get_title() + ' created.';  
    alert(result);  
}  

function onQueryFailed(sender, args) {  
    alert('Request failed. ' + args.get_message() +   
        '\n' + args.get_stackTrace());  
}  

\

1

IN YOUR CASE: var AppPath ; just below the script tag. as we know by coding standard we will generally declare all our global constant value in a starting of any function or code. this will resolve your problem. when you are using "var x=1" in a function its scope is limited to function. and when you create same out side the function its scope is global.

Your Answer

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

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