Skip to content

Instantly share code, notes, and snippets.

@vaderj
vaderj / updateSharePoint_ScreenWithoutRefresh.js
Last active June 12, 2018 17:03
screen update without refresh (with SP) #Javascript #SharePoint
function clearPostBack() {
$get('__EVENTTARGET').value = $get('__EVENTARGUMENT').value = '';
Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(clearPostBack);
// TODO: anything you want after __doPostBack
iterateList(jQuery("#scriptWPQ2 > table[summary='Resource Library'] > tbody > tr")) ;
}
function myPostBack(eventTargetClientId, eventArgument) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(clearPostBack);
@vaderj
vaderj / rejectSPdoc.js
Last active June 12, 2018 15:00
reject a SP document #Javascript #REST #SharePoint
function rejectDocument(docId)
{
jQuery.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Resource Library')/items(" + docId + ")/file/deny('Rejected')",
type: "POST",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
},
@vaderj
vaderj / Add-webpart-to-pubPage.ps1
Last active June 12, 2018 17:00
Add a web part to a publishing page #PowerShell #SharePoint
############
#
# From:
# http://www.sharepointpals.com/post/How-to-Add-WebPart-to-the-Publishing-Page-using-PowerShell-in-SharePoint-2013
#
#
############
# Add PowerShell Snapin
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
@vaderj
vaderj / Direwold_ScreenStartup
Last active June 12, 2018 17:03
Direwolf Raspberry Pi RasPi startup with Screen rtl sdr #BASH #Linux #pi
#In the dw-start.sh script, change the DWCMD definition to read:
#
#DWCMD="screen -dm -S direwolf bash -c 'rtl_fm -f 144.39M - | direwolf -c sdr.conf -r 24000 -D 1 -'"
#
#
# And then, as that command is ran via cron, you can access that screen via:
#
# screen -r direwolf
#
@vaderj
vaderj / SPInfoBar.js
Last active June 12, 2018 17:02
SharePoint information bar #Javascript #SharePoint
// Information bar
// https://msdn.microsoft.com/en-us/pnp_articles/customize-your-sharepoint-site-ui-by-using-javascript
//
function RemoteManager_Inject() {
loadScript(jQuery, function () {
$(document).ready(function () {
var message = "<img src='/_Layouts/Images/STS_ListItem_43216.gif' align='absmiddle'> <font color='#AA0000'>JavaScript customization is <i>fun</i>!</font>"
// Execute status setter only after SP.JS has been loaded
@vaderj
vaderj / SP-New-Item-Form-Edits.js
Last active June 11, 2018 20:39
SharePoint new list item form - reading / hiding to fields with JavaScript / jQuery #Javascript #SharePoint
//Lookup Column: Allow multiple values
// jQuery Select:
jQuery("select[title='Vehicle']") ;
// read selected options
jQuery("select[title='Vehicle'] option:selected").text() ;
// Hide one of the OPTIONS in the drop down selector (addressed via value, NOT text):
jQuery("select[title='Vehicle'] option[value='2']").remove()
// Hide the field and its label from view
jQuery("select[title='Vehicle']").closest('tr').hide()
@vaderj
vaderj / newSPlistItemViaREST.js
Last active June 30, 2023 14:44
Add a new SP list item via REST API #Javascript #SharePoint #REST
function newEnrollment(firstName, lastName, email, team, classNameId )
{
var item = {
"__metadata": { "type": "SP.Data.EnrolleesListItem" }, // <=="type" derived from the target Lists name - getbytitle('Enrollees') = "SP.Data.EnrolleesListItem"
"Title": firstName,
"LastName": lastName,
"Team": team,
"Email": email,
"ClassNameId": classNameId
@vaderj
vaderj / SPOpenApprovalModalDialog.js
Last active June 30, 2023 14:44
Open a SharePoint out of box Approval dialog #Javascript #SharePoint
function openApproveModal(docId)
{
//NavigateToApproveRejectAspx(event, &#39;' + _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/approve.aspx?List={4DBD7524-4A5F-49BF-B105-F139B4CA8983}&ID=' + docId + '&RootFolder=' + fileFolderEncoded + '&#39; )
fileName = jQuery("#" + docId + " a")[0].pathname ;
fileNameEncoded = fileName.replace(/\//g,"%2F") ;
fileFolderEncoded = fileName.replace(fileName.split('/')[fileName.split('/').length-1],"").slice(0,-1).replace(/\//g,"%2F") ;
var url = _spPageContextInfo.webAbsoluteUrl + '/_layouts/15/approve.aspx?List={' + listId + '}&ID=' + docId + '&RootFolder=' + fileFolderEncoded
@vaderj
vaderj / New SPListItem via SPREST API.js
Last active June 30, 2023 14:43
New SPListItem via SPREST API #Javascript #REST #SharePoint
function newEnrollment(firstName, lastName, email, team, classNameId )
{
var item = {
"__metadata": { "type": "SP.Data.EnrolleesListItem" },
"Title": firstName,
"LastName": lastName,
"Team": team,
"Email": email,
"ClassNameId": classNameId
};
@vaderj
vaderj / Delete-SPListItem.js
Last active June 12, 2018 15:10
Delete SharePoint List Item #Javascript #REST #SharePoint
function removeEnrollment(userId,listItemID)
{
var removeUserFromClass = jQuery.ajax({
//url: webUrl + "_api/web/lists/getbytitle('" + classesListName + "')/items?'" + classesColumns + "'&$filter=Title eq '" + lookup + "'" ,
url: webUrl + "_api/web/lists/getbytitle('Enrollees')/items(" + listItemID + ")",
method: "POST",
headers:
{
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"IF-MATCH": "*",