I am working on the below function in Javascript to pull data from two separate lists on SharePoint and pass the resultant data to another function. I've spent the past few hours trying to debug this function with the following error:
jQuery.Deferred exception: Duplicate parameter name not allowed in this context SyntaxError: Duplicate parameter name not allowed in this context at Array.
and am told the error is occurring at this line:
successFunction(RecordResponse, RecordAmountResponse)
Strangely, it do passed through both of the .done functions and output their respective check flags, yet I know I cannot change the parameters in the .then(function() { } ) otherwise my successFunction won't receive the response data it needs.
Here is the function that I am calling:
function getReportData(strRecordQuery, strRecordAmountQuery, successFunction, failFunction) {
// Use promise methods to run getListQuery from both tblRecord and tblRecordData
var RecordDataInfo = $.Deferred();
var RecordAmountDataInfo = $.Deferred();
var dfdRecordDataFiles;
var dfdRecordAmountDataFiles;
dfdRecordDataFiles = getListQuery('lstRecord', strRecordQuery, true);
dfdRecordAmountDataFiles = getListQuery('lstRecordAmount', strRecordAmountQuery, true);
dfdRecordDataFiles.done(function(RecordDataResponse) {
console.log("dfdRecordDataFiles.done");
RecordDataInfo.resolve(RecordDataResponse);
});
dfdRecordAmountDataFiles.done(function(RecordAmountDataResponse) {
console.log("dfdRecordAmountDataFiles.done");
RecordAmountDataInfo.resolve(RecordAmountDataResponse);
});
dfdRecordDataFiles.fail(function(error) {
console.log("dfdRecordDataFiles.fail");
console.log("ResponseText: " + error.responseText);
console.log(JSON.stringify(error));
RecordDataInfo.fail(error);
});
dfdRecordAmountDataFiles.fail(function(lerror) {
console.log("dfdRecordAmountDataFiles.fail");
console.log("ResponseText: " + lerror.responseText);
console.log(JSON.stringify(lerror));
RecordAmountDataInfo.fail(lerror);
});
$.when(RecordDataInfo, RecordAmountDataInfo)
.then(function(RecordResponse, RecordAmountResponse) {
successFunction(RecordResponse, RecordAmountResponse)
}, function(error, lerror) {
failFunction(error, lerror);
});
};
Can I get a second set of eyeballs to help me, as mine are getting tired of staring at this and not getting it.
Edit
I modified my code as per suggestion but am getting similar error:
function getListQuery(listName, queryString) {
// REST Call
return $.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items?" + queryString,
type: "GET",
headers: { ACCEPT: "application/json;odata=verbose" }
});
};
function getReportData(strRecordQuery, strRecordAmountQuery, strRecordPersonnelQuery) {
return $.when(getListQuery('lstRecord', strRecordQuery, true), getListQuery('lstRecordAmount', strRecordAmountQuery, true), getListQuery('lstRecordPersonnel', strRecordPersonnelQuery, true))
};
function setReportQueries(Yr0, Yr1, Yr2, Yr3, Yr4) {
// Specific to the report
strRecordQuery = "$select=ID,RecordName";
strRecordAmountQuery = "$select=ID,Parameter1,Year,Amount&$filter=(Year eq '" + Yr0 + "') or (Year eq '" + Yr1 +
"') or (Year eq '" + Yr2 + "') or (Year eq '" + Yr3 + "') or (Year eq '" + Yr4 + "')";
strRecordPersonnelQuery = "$select=ID, Parameter1&$filter=(Year eq '" + Yr0 + "') or (Year eq '" + Yr1 +
"') or (Year eq '" + Yr2 + "') or (Year eq '" + Yr3 + "') or (Year eq '" + Yr4 + "')";
getReportData(strRecordQuery, strRecordAmountQuery, strRecordPersonnelQuery).then(loadReportTables);
};
function loadReportTables(RecordData, RecordAmountData, RecordPersonnelData) {
console.log("Enter loadReportTables()");
/* Do Stuff */
}
The error I am getting is:
jQuery.Deferred exception: Duplicate parameter name not allowed in this context SyntaxError: Duplicate parameter name not allowed in this context at l (https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js:2:29375) at c (https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js:2:29677) undefined