Crow Canyon Power Portal
Portal Tile Custom Javascript Code
Update tile text and URL based on logged in user and the status of a list item
// Parameters: // spContext: SharePoint client context object that can be used to get data from the sites // paramTileInfo: This object has the information to render tiles with values as set in the portal settings. Override the specific attributes for custom rendering // paramUserID: Current logged in user ID // functionCallback: This function should be called after setting the tile attributes to return the control back to portal framework // In below example, the text and link of tile is changed after querying data based on logged in user and the state of data var webURL = "https://xxxxxxxxxx.sharepoint.com/sites/Corporate/ClientOnboarding"; var ClientDataListName = "Client Data"; var ClientDataListUserColumnName = "Client"; var RequestLookupColumn = "ComplianceRequest"; var RequestListStatusColumn = "CalComplianceStatus"; var clientDataEditPageURL = "https://xxxxxxxxxxxx.sharepoint.com/sites/Corporate/ClientOnboarding/portal/SitePages/EditForm.aspx?pid=1"; var clientDataDisplayPageURL = "https://xxxxxxxxxxxx.sharepoint.com/sites/Corporate/ClientOnboarding/portal/SitePages/DisplayForm.aspx?pid=1"; var statusValueForEdit = "Pending Check Point 1"; var RequestItemIdQuery = webURL + "/_api/web/Lists/getByTitle('" + ClientDataListName + "')/Items?$select=ID,Title" + "," + RequestLookupColumn + "/" + RequestListStatusColumn + "&$expand=" + RequestLookupColumn + "/Id&$Filter=" + ClientDataListUserColumnName + "/Id%20eq%20" + paramUserID + "&$orderby=Created%20desc&$top=1"; $.ajax ({ url : RequestItemIdQuery, method : "GET", headers : { "Accept" : "application/json; odata=verbose" }, success : function (data) { if (data.d.hasOwnProperty("results") && data.d.results.length > 0) { var listItem = data.d.results[0]; var requestStatus = ""; if (listItem[RequestLookupColumn]) { requestStatus = listItem[RequestLookupColumn][RequestListStatusColumn]; } if (requestStatus == statusValueForEdit) { paramTileInfo.URL = clientDataEditPageURL + "&ItemID=" + listItem.ID; // Set tile URL as per the status } else { paramTileInfo.URL = clientDataDisplayPageURL + "&ItemID=" + listItem.ID; } } else { paramTileInfo.URL = " "; paramTileInfo.Text = "Onboarding process not initiated"; // set tile text depending on whether current user has any data or not } functionCallback(paramTileInfo); // Always call back this function with tiles data to return the control to portal }, error : function () { functionCallback(paramTileInfo); }, async : true });
Privacy Statement
Contact Us
Developed by
Copyright © 2018 Crow Canyon Systems, Inc. All Rights Reserved.