Skip to content

Instantly share code, notes, and snippets.

View durgesh97025's full-sized avatar

Rahul Gupta durgesh97025

View GitHub Profile
@durgesh97025
durgesh97025 / parseTaxonomySearchResultValue.js
Created December 8, 2016 13:25
Parse Taxonomy Value From Search Results. Used in Search Result Item Display Template
function parseTaxonomySearchResultValue(val){
var taxValue = {TermSetGuids: [], TermValues: []};
var parts = val.split(';');
parts.forEach(function(part){
if (part.startsWith("GP0|#")) //term?
{
var termGuid = part.replace("GP0|#", "");
taxValue.TermValues.push({ TermGuid: termGuid});
}
else if (part.startsWith("GTSet|#")) //term set?
@durgesh97025
durgesh97025 / JsonToTable.js
Created November 17, 2016 15:57
Create Json to HTML Table plugin and example.
var rextension = {
CreateTableFromJson: function (options){
/*
var options ={
data: results,
container: "#jsontotable",
FieldNotToPopulate: ["id","uri","etag","type","Id","TermGuid","type","Label","WssId"]
};
*/
console.log(options);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
<%@ Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Diable Thrid Level TermSet</title>
<meta http-equiv="X-UA-Compatible" content="IE=10" />
//An Example of Using SPTrick, uses SetValueForPeoplPicker & GetFieldControl
$.when( $.SetValueForPeoplPicker('Requestor',G_CurrentUserEmail)).then(function(){
$.GetFieldControl('Requestor').attr("disabled","disabled").find(".sp-peoplepicker-delImage").hide();
});
@durgesh97025
durgesh97025 / GetUserProfileProperties.js
Last active October 7, 2016 14:34
Get User Profile Properties of Current User and Specified User
function GetUserProfileProperties() {
var userProfileProperties;
var peopleManager = new SP.UserProfiles.PeopleManager(rClientContext);
userProfileProperties = peopleManager.getMyProperties();
rClientContext.load(userProfileProperties);
rClientContext.executeQueryAsync(onRequestSuccess, onRequestFail);
function onRequestSuccess() {
//https://unicef-my.sharepoint.com/_layouts/15/EditProfile.aspx?UserSettingsProvider=dfb95e82-8132-404b-b693-25418fdac9b6
//The list of properties
@durgesh97025
durgesh97025 / ProgressDialog.js
Last active July 7, 2023 15:28
Show Progress Bar in Dialog. Useful during ajax operations
$(document).ready(function(){
$("BODY").append('<div id="dialog-message" title="In Progress">\
<div id="progressbar"></div>\
</div>');
});
function ShowDialog() {
$( "#dialog-message" ).dialog({
dialogClass: "no-close",
modal: true
@durgesh97025
durgesh97025 / RegionCountryFromPlace.js
Created September 29, 2016 12:55
Get Region and Country from Place
log("CountryRegion");
function AddCountryToField(dutyStationFieldName,countryFieldName,regionFieldName){
var d = $.Deferred();
var DutyStationTermsetName = "6e8c6e86-6359-4685-9284-1fcbf0629093"; //DutyStationTermsetID
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(rClientContext);
var termStores = taxSession.get_termStores();
var termStore = taxSession.getDefaultSiteCollectionTermStore();
var termSet = termStore.getTermSet(DutyStationTermsetName);
@durgesh97025
durgesh97025 / DisableTaxonomy.js
Last active September 26, 2016 12:44
Disable Taxonomy Field Control in SPOnline
$("[ID*='RequestorDutyStation']").find('[contenteditable]').attr('contenteditable','false').end().find('IMG').hide();
@durgesh97025
durgesh97025 / EmailFrmSharePoint.js
Created September 20, 2016 11:25
Email using REST API into SharePoint
console.log("Email");
function sendEmail(from, to, body, subject) {
//Get the relative url of the site
var d = $.Deferred();
var siteurl = _spPageContextInfo.webServerRelativeUrl;
var urlTemplate = siteurl + "/_api/SP.Utilities.Utility.SendEmail";
$.ajax({
contentType: 'application/json',
@durgesh97025
durgesh97025 / SPTrick.js
Last active April 25, 2017 07:58
An Js file for SharePoint for speedy development
if (typeof console == "undefined") { this.console = {log: function() {}}; }//If browser doesn't support console.log
//OTO = One Time Object
var rClientContext;//A context OTO used everywhere
var rWeb;//A web OTO used
var rCurrentUser;// A user OTO
$(document).ready(function(){
rClientContext = SP.ClientContext.get_current();
rWeb = rClientContext.get_web();