Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");
- function initializePage()
- {
- var context = SP.ClientContext.get_current();
- var user = context.get_web().get_currentUser();
- var context;
- var hostweburl;
- var appweburl;
- var appContextSite;
- var list;
- var employeeList;
- var web;
- var collListItem;
- var collListItem1;
- var isManager = false;
- var requestList;
- // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
- $(document).ready(function ()
- {
- getUserName();
- SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUrl);
- });
- // This function prepares, loads, and then executes a SharePoint query to get the current users information
- function getUserName()
- {
- context.load(user);
- context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
- }
- // This function is executed if the above call is successful
- // It replaces the contents of the 'message' element with the user name
- function onGetUserNameSuccess()
- {
- $('#message').text('Hello ' + user.get_title());
- }
- // This function is executed if the above call fails
- function onGetUserNameFail(sender, args) {
- alert('Failed to get user name. Error:' + args.get_message());
- }
- function getUrl() {
- hostweburl = getQueryStringParameter("SPHostUrl");
- hostweburl = hostweburl.replace("%2FUserInbox","");
- appweburl = getQueryStringParameter("SPAppWebUrl");
- hostweburl = decodeURIComponent(hostweburl);
- appweburl = decodeURIComponent(appweburl);
- alert(hostweburl);
- alert(appweburl);
- var scriptbase = hostweburl + "/_layouts/15/";
- alert(scriptbase);
- $.getScript(scriptbase + "SP.Runtime.js",
- function () {
- $.getScript(scriptbase + "SP.js",
- function () { $.getScript(scriptbase + "SP.RequestExecutor.js", execOperation); }
- );
- }
- );
- event.preventDefault();
- }
- function execOperation()
- {
- context = new SP.ClientContext(appweburl);
- var factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
- context.set_webRequestExecutorFactory(factory);
- appContextSite = new SP.AppContextSite(context, hostweburl);
- web = appContextSite.get_web();
- context.load(web);
- employeeList = web.get_lists().getByTitle("Employees");
- console.log(employeeList);
- var camlQuery = new SP.CamlQuery();
- camlQuery.set_viewXml(
- "<View><Query><Where><Eq><FieldRef Name='EmployeeName' /><Value Type='User'>" + user.get_title() + "</Value></Eq></Where></Query></View>"
- );
- collListItem1 = employeeList.getItems(camlQuery);
- context.load(collListItem1);
- var listItemEnumerator = collListItem1.getEnumerator();
- while (listItemEnumerator.moveNext()) {
- console.log("Here");
- var oListItem = listItemEnumerator.get_current();
- listItemInfo += '\n Employee: ' + oListItem.get_item('EmployeeName')['$5K_1'];
- console.log(oListItem.get_item('Employee'));
- console.log(oListItem.get_item('Manager'));
- }
- //GET EMPLOYEE TYPE
- getEmployeeType();
- }
- function getEmployeeType()
- {
- // employeeList = web.get_lists().getByTitle("Employees");
- // console.log(employeeList);
- // var camlQuery = new SP.CamlQuery();
- // camlQuery.set_viewXml(
- //"<View><Query><Where><Eq><FieldRef Name='EmployeeName' /><Value Type='User'>" + user.get_title() + "</Value></Eq></Where></Query></View>"
- //);
- // collListItem1 = employeeList.getItems(camlQuery);
- // context.load(collListItem1);
- // var listItemEnumerator = collListItem1.getEnumerator();
- // while (listItemEnumerator.moveNext())
- // {
- // console.log("Here");
- // var oListItem = listItemEnumerator.get_current();
- // listItemInfo += '\n Employee: ' + oListItem.get_item('EmployeeName')['$5K_1'];
- // console.log(oListItem.get_item('Employee'));
- // console.log(oListItem.get_item('Manager'));
- // }
- }
- function getRequests()
- {
- list = web.get_lists().getByTitle("AppraisalRequests");
- var camlQuery = new SP.CamlQuery();
- if (isManager == true) {
- }
- else
- {
- }
- }
- //function execOperation()
- //{
- // list = web.get_lists().getByTitle("AppraisalRequests");
- // alert(list.count);
- // alert(employeeList.count);
- // var camlQuery = new SP.CamlQuery();
- // camlQuery.set_viewXml(
- // '<View><Query><Where><IsNotNull><FieldRef Name="ID"/></IsNotNull></Where></Query></View>'
- // );
- // collListItem = list.getItems(camlQuery);
- // console.log(user.get_title());
- // context.load(collListItem);
- // context.executeQueryAsync(onSuccess, onFail);
- //}
- function onSuccess()
- {
- alert("List loaded Successfully");
- var count = collListItem.get_count();
- alert(count);
- var listItemInfo = '';
- var listItemEnumerator = collListItem.getEnumerator();
- while (listItemEnumerator.moveNext())
- {
- // alert("Enter");
- var oListItem = listItemEnumerator.get_current();
- // alert(oListItem.get_id());
- listItemInfo += '\n Manager: ' + oListItem.get_item('Manager')['$5K_1']+
- '\n Employee: ' + oListItem.get_item('Employee')['$5K_1'];
- console.log(oListItem.get_item('Manager'));
- console.log(oListItem.get_item('Employee'));
- }
- alert(listItemInfo.toString());
- alert("Here");
- var count = collListItem1.get_count();
- alert(count);
- var listItemInfo = '';
- var listItemEnumerator = collListItem1.getEnumerator();
- while (listItemEnumerator.moveNext()) {
- // alert("Enter");
- var oListItem = listItemEnumerator.get_current();
- // alert(oListItem.get_id());
- listItemInfo += '\n Employee: ' + oListItem.get_item('EmployeeName')['$5K_1'];
- console.log(oListItem.get_item('EmployeeName'));
- console.log(oListItem.get_item('EmployeeType'));
- if (oListItem.get_item('EmployeeType') == "Manager")
- {
- isManager = true;
- }
- }
- alert(isManager);
- alert(listItemInfo.toString());
- getRequests();
- }
- // This function is executed if the above call fails
- function onFail(sender, args) {
- alert(args.get_message());
- }
- function getQueryStringParameter(paramToRetrieve) {
- var params =
- document.URL.split("?")[1].split("&");
- for (var i = 0; i < params.length; i = i + 1) {
- var singleParam = params[i].split("=");
- if (singleParam[0] == paramToRetrieve)
- return singleParam[1];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement