I have two external lists connected via external content types which are connected to stored procedures in SQL Server. I believe I have them set up identically (though evidently not because one is not working).
the working procedure looks like this
select id = row_number() over (order by U.UserID)
, UserIdValue = U.UserID
, UserIdDisplay = '@userId=' + @userId
, SiteIdValue = U.SiteID
, SiteIdDisplay = U.SiteID
from User_Site U
INNER JOIN Final_Site F On F.SiteID=U.SiteID
where U.UserID = coalesce(@userId,U.UserID)
and when I call it through the REST API like this
var listName = 'SiteListForUser'
var itemType = "SP.Data." + listName.charAt(0).toUpperCase() + listName.split(" ").join("").slice(1) + "ListItem";
var item = {
"__metadata": { "type": itemType }
};
$.ajax({
type: 'GET',
contentType: "application/json;odata=verbose",
url: "myUrl/_api/web/lists/getbytitle('SiteListForUser')/items?$filter=(SiteIdValue eq 'aSiteId') and (UserIdValue eq 'MyUserName')&$top=200",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
},
async: "false",
success: function (data) {
console.log(data);
}
});
data.d.results
has one record (as expected) and it is
{
[functions]: ,
__metadata: { },
AttachmentFiles: { },
BdcIdentity: "_bunchofnumbers",
ContentType: { },
FieldValuesAsHtml: { },
FieldValuesAsText: { },
FieldValuesForEdit: { },
File: { },
FileSystemObjectType: 0,
FirstUniqueAncestorSecurableObject: { },
Folder: { },
Id: 0,
ParentList: { },
RoleAssignments: { },
SiteIdDisplay: "aSiteId",
SiteIdValue: "aSiteId",
UserIdDisplay: "@userId=myUserName",
UserIdValue: "myUserName"
}
so far so good. Now my second stored procedure looks like this
select top 2000 id = ROW_NUMBER() over (order by U.UserId, U.SiteId, F.TaskId)
, UserIdValue = U.UserID
, UserIdDisplay = '@userId=' + @userId
, SiteIdValue = U.SiteID
, SiteIdDisplay = '@siteId=' + @siteId
, TaskIdValue = F.TaskID
, TaskIdDisplay = F.TaskID
from User_Site U
INNER JOIN Final_Site_Task F On F.SiteID=U.SiteID
where U.UserID= coalesce(@userId, U.UserID)
and U.SiteId= coalesce(@siteId, U.SiteId)
and when I call it from JS
var listName = 'TaskListForUserSite'
var itemType = "SP.Data." + listName.charAt(0).toUpperCase() + listName.split(" ").join("").slice(1) + "ListItem";
var item = {
"__metadata": { "type": itemType }
};
$.ajax({
type: 'GET',
contentType: "application/json;odata=verbose",
url: "myUrl/_api/web/lists/getbytitle('TaskListForUserSite')/items?$filter=(SiteIdValue eq 'aSite') and (UserIdValue eq 'myUserName')&$top=200",
data: JSON.stringify(item),
headers: {
"Accept": "application/json;odata=verbose",
},
async: "false",
success: function (data) {
console.log(data);
}
});
I get 0 results in data.d.results
. If I remove the top 2000
from my stored procedure I get an error because BCS can't return more then 2000 results. I then try (with the top
back in place)
"myUrl/_api/web/lists/getbytitle('TaskListForUserSite')/items?$filter=(SiteIdValue eq 'aSite')"
Where I get 26 results but each one looks basically like this
{
[functions]: ,
__metadata: { },
AttachmentFiles: { },
BdcIdentity: "__bunchofnumbers",
ContentType: { },
FieldValuesAsHtml: { },
FieldValuesAsText: { },
FieldValuesForEdit: { },
File: { },
FileSystemObjectType: 0,
FirstUniqueAncestorSecurableObject: { },
Folder: { },
Id: 0,
ParentList: { },
RoleAssignments: { },
SiteIdDisplay: null,
SiteIdValue: "aSiteId",
TaskIdDisplay: "a task Id 123",
TaskIdValue: "a task Id 123",
UserIdDisplay: null,
UserIdValue: "myUserName"
}
notice that SiteIdDisplay and UserIdDisplay are null indicating that my filter parameters did not get passed to the stored procedure at all. Instead all the 'filtering' was done after the results were returned to BCS.
So how do I set up my external content type so that input parameters are mapped to stored procedure parameters?