I am using below code to retrieve data from my list:
$http({
method: 'GET',
url: _spPageContextInfo.webAbsoluteUrl+"/_api/web/lists/getbytitle('Mylist')/items?$select=*,Resource/ID&$expand=Resource&$filter=(Resource/ID eq "+ resId +")&$orderby=EndDate desc",
headers: {
'Accept': 'application/json; odata=verbose'
}
}).success(function (d) {
dataM = [];
$(d.d.results).each(function (i, e) {
dataM.push({
id: e['Id'],
StartDate: svc.formatDate(new Date(e['StartDate'])),
EndDate: svc.formatDate(new Date(e['EndDate'])),
ResourceDailyRate: e['Resource_x0020_Daily_x0020_Rate'],
ClientDailyRate: e['Client_x0020_Daily_x0020_Rate'],
PoliceCheck : ((e['Police_x0020_Check'] == null || e['Police_x0020_Check'] == 'Select')? 'X' : e['Police_x0020_Check']),
CreatedClientContract: (e['Created_x0020__x0028_Client_x002'] == null ? 'X' : e['Created_x0020__x0028_Client_x002']),
SignedApproved: (e['Signed_x002f_Approved_x0020__x00'] == null ? 'X' : e['Signed_x002f_Approved_x0020__x00']),
CounterSigned: (e['Countersigned_x0020__x0028_Clien'] == null ? 'X' : e['Countersigned_x0020__x0028_Clien']),
SignedResource : (e['Signed_x0020__x0028_Resource_x00'] == null ? 'X' : e['Signed_x0020__x0028_Resource_x00']),
CounterSignedResource : (e['Countersigned_x0020__x0028_Resou'] == null ? 'X' : e['Countersigned_x0020__x0028_Resou']),
PORecieved : (e['PO_x0020_Recieved'] == null ? 'X' : e['PO_x0020_Recieved']),
ReoccurringInvoice : (e['Reoccurring_x0020_Invoice'] == null ? 'X' : e['Reoccurring_x0020_Invoice']),
DocType: e['Doc_x0020_Type'],
DocID: e['Doc_x0020_ID'],
PONumber :e['PO_x0020_Number']
});
});
console.log('dataM',dataM);
callback(dataM);
deferred.resolve(dataM);
}).error(function (er) {
alert(er);
});
}
It works as expected except it is giving me 1 day earlier date in start & end date. Can anyone suggest some work around?
In svc.formatDate
function I tried below code:
svc.formatDate = function (dt) {
var options = {
day: "numeric", month: "long", year: "numeric"
};
return dt.toLocaleDateString('en-AU', options);
}
Also I have checked JSON.stringify
& JSON.parse
in other stack overflow blogs. but its not helping.