Skip to content

Instantly share code, notes, and snippets.

View durgesh97025's full-sized avatar

Rahul Gupta durgesh97025

View GitHub Profile
$(document).ready(function() {
//SP.SOD.executeOrDelayUntilScriptLoaded(AddCustomUserAction, "sp.js");
SP.SOD.executeOrDelayUntilScriptLoaded(DeleteCustomActions, "sp.js");
});
function DeleteCustomActions() {
var listTitle = "Pension Files";
context = new SP.ClientContext();
var web = context.get_web();
var list = context.get_web().get_lists().getByTitle(listTitle);
@durgesh97025
durgesh97025 / CurrentUserPermissionCheck.js
Created October 3, 2017 13:46
Current User Permission Check on SPWeb
$(document).ready(function(){
$.when(checkPermissions()).then(function(isOnlyContributor){
if (isOnlyContributor){
setInterval(HideSiteContents, 1000);
}
});
});
function HideSiteContents(){
console.log($("SPAN:contains('Site contents')").length + " called");
@durgesh97025
durgesh97025 / PermissionManage.js
Created July 27, 2017 11:57
Manage Item Permission, Break, Assign New Role, Remove Existing Role
function PreSaveAction(){
var status = $("[Title~='Status']").val();
if (status == "Final"){
var groupName = "XXX Owners"
PermissionManager.BreakInheritance().then(function(data){
console.log("Permission Inheritance Breaked with roles and groups");
}).fail(function(error){
console.log(error);
}).then(function (){
@durgesh97025
durgesh97025 / SPO-FileUpload.js
Created May 31, 2017 12:10
File Upload/Copy from another Http Url in SharePoint Online using REST and jQuery
var SourceList = "SourceList";
var DestinationList = "DestinationList";
$(document).ready(function() {
exec();
$("#myBtn").click(exec);
});
function exec() {
var sourceId = 12;
var sourceAttachmentUrl = _spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('" + SourceList + "')/Items('" + sourceId + "')/Attachmentfiles";
@durgesh97025
durgesh97025 / SPOLogin.cs
Last active May 30, 2017 08:42
SharePoint Online Login using Httpwebrequest via .net 3.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Xml.Linq;
using System.IO;
using System.Security;
using System.Xml;
@durgesh97025
durgesh97025 / Field_Hide_show.js
Created March 24, 2017 11:52
Field Disable/Enable for NewForm/EditForm
//https://msdn.microsoft.com/en-us/library/office/dn600182.aspx#bk_FieldSetShowInNewForm
//https://msdn.microsoft.com/en-us/library/office/jj838353.aspx
//<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
//<script>
$(document).ready(function(){
var url = "https://unicef.sharepoint.com/teams/DFAM/BudgetSection/_api/web/Lists/getByTitle('XXX')/Fields(guid'XXX')/setShowInNewForm(false)";
$.ajax({
url: url,
contentType: "application/json;odata=verbose",
@durgesh97025
durgesh97025 / Rest.txt
Last active January 12, 2018 15:29
REST API Example
https://xxx.sharepoint.com/sites/Site/Web/_api/SP.UserProfiles.PeopleManager/GetMyProperties
SharePoint Navigation: _spPageContextInfo.webAbsoluteUrl + '/_api/web/Navigation/GetNodeById(1040)/Children
Quick Launch: _spPageContextInfo.webAbsoluteUrl + '/_api/Web/Navigation/GetNodeById(1031)/Children
QuickLaunch EndPoint :/_api/web/Navigation/QuickLaunch
TopNavigation EndPoint: /_api/web/Navigation/TopNavigationbar
Filters on List/Libraray: /_api/web/lists?$filter=IsCatalog eq false and Hidden eq false and BaseType eq 1&$Select=Title,DocumentTemplateUrl
@durgesh97025
durgesh97025 / Utility.js
Last active March 21, 2023 15:07
Utility for Array, String
String.prototype.replaceAll = function(search, replacement) {
var target = this;
return target.replace(new RegExp(search, 'g'), replacement);
};
Array.prototype.contains = function(v) {
for(var i = 0; i < this.length; i++) {
if(this[i] === v) return true;
}
return false;
@durgesh97025
durgesh97025 / PreSaveAction_AjaxCall.js
Created December 26, 2016 14:53
How to Call Ajax Function in PreSaveAction without any dependencies
var G_IsUpdatePending = true;
function PreSaveAction(){
AssignQuarter();
if (G_IsUpdatePending){
var dutyStation = GetSelectedTermText('Office')
if (dutyStation){
ShowDialog();
$.when(AddCountryToField('Office','Country_','Region_')).then(function(){
@durgesh97025
durgesh97025 / SP Online Url Info.js
Created December 13, 2016 14:48
SP Online Url Info.js
_spPageContextInfo.siteAbsoluteUrl;
_spPageContextInfo.siteServerRelativeUrl;
_spPageContextInfo.webAbsoluteUrl;
_spPageContextInfo.webServerRelativeUrl;