Edit 12/4: I'm also attempted to get the site page url from another list but also giving me an error each time it tries to open the page from SitePages library. (Posted here)
I'm trying to dynamically create a link to open the appropriate calendar view based on current users
- List: Staff Directory; Columns: EmailAddress, Section
- Library: SitePages; Columns: Name, Section
The code below works to get the section name of the current user:
$(function(){
var currentUserEmail = _spPageContextInfo.userEmail;
var requestSecUrl = "https://site/_api/web/Lists/getByTitle('StaffDirectory')/Items?$filter=Title eq '" + currentUserEmail + "'&$select=Section";
$.ajax({
url: requestUrl,
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var mySection = data.d.results[0].Section
alert(mySection);
},
error: function (data) {alert ("error found"); }
});
But how do I use the 'mySection' to filter the library and return the filename?
I tried adding the following after the alert(my Section);
var calSecUrl = "https://site/_api/web/Lists/getByTitle('SitePages')/Items?$filter=Section eq '" + mySection + "'&$select=FileLeafRef";
$.ajax({
url: calSecUrl,
method: "GET",
async: false,
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var CalFileName = data.d.results[0].FileLeafRef;
alert(CalFileName);
},
error: function (data) {alert("Calendar not found");}
});
I keep getting the "Calendar not found" alert.
FileLeafRef
try this:http://site/_api/web/Lists/GetByTittle('DocLibName')/items?$select=FieldValuesAsText/FileLeafRef&$expand=FieldValuesAsText
"/_api/web/Lists/getByTitle('SitePages')/Items?$select=FileLeafRef&$expand=FieldValuesAsText";