I've read multiple articles about returning a promise from a promise handler to resolve data dependencies. But when I run the following code instead of the done handler returning another promise foobar still contains the results of the first promise, it is as if it ignores my return:
function sharepointRestCall( type, endpoint, headers, data ){
return $.ajax({
type: type,
url: url + endpoint ,
dataType: "json",
headers: headers,
data: JSON.stringify( data )
});
}
function pwaRestCall( type, endpoint, headers, data ){
return $.ajax({
type: type,
url: url + endpoint ,
dataType: "json",
headers: headers,
data: JSON.stringify( data )
});
}
var listColumns;
var permission;
var projectGuid;
/*Create a project for this item using information from Nomination REST TEST */
//Read the nomination list
sharepointRestCall(
"POST",
"lists(guid'318382F9-0A5B-45B7-80D1-9527C9327513')/RenderListDataAsStream",
{ "accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=nometadata"},
{'parameters': { 'RenderOptions': 2, 'ViewXml': "<View><Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + getQueryParam("Id") +"</Value></Eq></Where></Query><ViewFields><FieldRef Name='Title' /><FieldRef Name='Business_x0020_Area' /><FieldRef Name='PM' /><FieldRef Name='DirectorName' /><FieldRef Name='Project_x0020_Description' /><FieldRef Name='RiskImpact' /></ViewFields><QueryOptions /></View>"}}
)
.done( function( nomDataList ){
listColumns = nomDataList.Row[0];
//we need the sharepoint list results AND permission to modify before doing anything else
return pwaRestCall( "POST", "contextinfo", { "Accept": "application/json; odata=verbose"}, "" );
}).then(function ( foobar){
console.log(foobar); // <-- contains nomDataList instead of the result of pwaRestCall
});
I'm trying to implement what I've read nested promises, stackoverflow, promise chaining but nothing has worked so far even if I wrap pwaRestCall with $.when, which I think is the equivalent of promise.all, or attach a done handler.