Below is the Query to get the Items,
- camlQuery.set_viewXml("<View><Query><Where><Or><Membership Type=\"CurrentUserGroups\"><FieldRef Name=\"AssignedTo\"/></Membership><Eq><FieldRef Name=\"AssignedTo\"></FieldRef><Value Type=\"Integer\"><UserID/></Value></Eq></Or></Where></Query></View>");
Use the below code to get the items from host web using SharePoint app,
Use strict:
-
-
- var hostWebURL, appWebURL;
-
-
- $(document).ready(function () {
-
- GetDatafromList();
-
- });
-
- function GetDatafromList() {
-
- hostWebURL = decodeURIComponent(manageQueryStringParameter('SPHostUrl'));
- appWebURL = decodeURIComponent(manageQueryStringParameter('SPAppWebUrl'))
- var context = new SP.ClientContext(appWebURL);
- var appCtxSite = new SP.AppContextSite(context, hostWebURL);
- var web = appCtxSite.get_web();
- var list = web.get_lists().getByTitle(‘TestList’);
- var camlQuery = new SP.CamlQuery();
- camlQuery.set_viewXml("<View><Query><Where><Or><Membership Type=\"CurrentUserGroups\"><FieldRef Name=\"AssignedTo\"/></Membership><Eq><FieldRef Name=\"AssignedTo\"></FieldRef><Value Type=\"Integer\"><UserID/></Value></Eq></Or></Where></Query></View>");
- var liscoll = list.getItems(camlQuery);
- context.load(liscoll);
- context.executeQueryAsync(function () {
- console.log("My Portfolio");
- var listItemCount = liscoll.get_count();
- if (listItemCount > 0) {
- var enumerator = liscoll.getEnumerator();
- while (enumerator.moveNext()) {
- var currentItems = enumerator.get_current();
- var title = currentItems.get_item("Title");
- console.log("Title is : " + title);
-
- }
- }
- }
- , function (sender, args) {
- console.log("List Items failed" + args.get_message());
- });
-
- }
-
- function manageQueryStringParameter(paramToRetrieve) {
- var params = document.URL.split("?")[1].split("&");
- var strParams = "";
- for (var i = 0; i < params.length; i = i + 1) {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve) {
- return singleParam[1];
- }
- }
- }
Make sure to provide permission for list in appmanifest.xml file as shown in below,
Summary
In this article we have explored how to get the list items for assigned to current user or to the group in which the current user is a member.