1

I want to call the following function in a selection event function name calcDay().

var p = getList("Compulsory Leave");

When i put it inside the selection event function it generated error : p is not defined.

Previously it put at above p.done(function(result) to execute.

Anyone can help?

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


function calcDay() 
{

   if(fd.field('Leave_x0020_Type').value() == 0)
   {
      fd.field('StartDate').value('HIHI');
   }

   else
   {
      //var p = getList("Compulsory Leave");
      //if i put here it generated error : p is not defined.
   }
}


function successCallback() {
this.d.resolve(this.listItem);
}

function failCallback() {
   this.d.reject("something bad happened");
}

function getList(name) {
   var d = $.Deferred();

   var clientContext = SP.ClientContext.get_current();
   var list = clientContext.get_web().get_lists().getByTitle(name);
   var camlQuery = new SP.CamlQuery();
   camlQuery.set_viewXml
   (
       '<View><Query><ViewFields><FieldRef Name=\'Title\'/>' +
       '</ViewFields></Query></View>'
   );
   var collListItem = list.getItems(camlQuery);
   clientContext.load(collListItem);
   var o = {d: d, list:list, listItem:collListItem};
   clientContext.executeQueryAsync(Function.createDelegate(o, successCallback), Function.createDelegate(o, failCallback));

   return d.promise();
 }

//previously put at here to execute
//var p = getList("Compulsory Leave");
p.done(function(result) {
console.log('done');

var listItem = result;
var listItemEnumerator = listItem.getEnumerator();
while (listItemEnumerator.moveNext()) 
    {
        var oListItem = listItemEnumerator.get_current();

        var getoList = oListItem.get_item('Title');
        console.log(getoList);
        //return getoList;

     }

 });

 p.fail(function(result) {

    var error = result;
    alert(error);
 });

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.