Project Server access using OData service
// Get Project data
function GetProjectData(filterValues) {
var d = $.Deferred();
var url = "https://epmo.dtz.com/Defence/_api/ProjectData/Projects?$select=ProjectName,ProjectIDCopy,ProjectDescriptor,DeliveryAgentProjectManager,ProjectDeliveryRegion,ProjectManagerName,TotalMultiYearbudget";
var filter = "";
// Creating the filter
for (var property in filterValues) {
if (filter && filterValues[property]) {
filter += " and ";
}
if (filterValues[property]) {
filter += "substring(" + property + ",0," + (Number(filterValues[property].length) - Number(1)) + ") eq" + "'" + filterValues[property] + "'"; // Building filter eg:substring(ProjectName, 1, 2) eq 'CA'
}
};
// If filter is not null append it to the url
if (filter) {
url = url + "&$filter=" + filter;
}
$.ajax({
url: url,
type: "GET",
contentType: "application/json",
headers: { "ACCEPT": "application/json;odata=verbose" },
}).done(function (response) {
d.resolve(response.d.results);
}).fail(function (xhr, textStatus, errorThrown) {
alert(xhr.responseText);
});
return d.promise();
};
function GetProjectData(filterValues) {
var d = $.Deferred();
var url = "https://epmo.dtz.com/Defence/_api/ProjectData/Projects?$select=ProjectName,ProjectIDCopy,ProjectDescriptor,DeliveryAgentProjectManager,ProjectDeliveryRegion,ProjectManagerName,TotalMultiYearbudget";
var filter = "";
// Creating the filter
for (var property in filterValues) {
if (filter && filterValues[property]) {
filter += " and ";
}
if (filterValues[property]) {
filter += "substring(" + property + ",0," + (Number(filterValues[property].length) - Number(1)) + ") eq" + "'" + filterValues[property] + "'"; // Building filter eg:substring(ProjectName, 1, 2) eq 'CA'
}
};
// If filter is not null append it to the url
if (filter) {
url = url + "&$filter=" + filter;
}
$.ajax({
url: url,
type: "GET",
contentType: "application/json",
headers: { "ACCEPT": "application/json;odata=verbose" },
}).done(function (response) {
d.resolve(response.d.results);
}).fail(function (xhr, textStatus, errorThrown) {
alert(xhr.responseText);
});
return d.promise();
};
Comments
Post a Comment
Your comments...