A part of the name from the guy you're looking for
Object
setupOptional
Options (see below)
String
setup.limitOptional, Default: 10
Number of results returned
String
setup.typeOptional, Default: 'User'
Possible values are: 'All', 'DistributionList', 'SecurityGroup', 'SharePointGroup', 'User', and 'None' (see http://msdn.microsoft.com/en-us/library/people.spprincipaltype.aspx)
String
setup.urlOptional, Default: 'current website'
The website url
Function
resultOptional
A function that will be executed at the end of the request with a param that is an array with the result (typically: AccountName,UserInfoID,DisplayName,Email,Departement,Title,PrincipalType)
Example:
$SP().addressbook("john", {limit:25}, function(people) {
for (var i=0; i < people.length; i++) {
for (var j=0; j < people[i].length; j++) console.log(people[i][j]+" = "+people[i][people[i][j]]);
}
});
One of the enumeration values specifying the result of the modal dialog, or the modal object returned by $SP().getModalDialog()
Object
returnValueOptional
The return value of the modal dialog
Example:
// if the user use the cross to close the modal, then `dialogResult` equals to 0 in the callback
// but you can trigger the close of the modal and pass anything you want
$SP().showModalDialog({
title:"Hello World",
html:'
A callback function that will be triggered after the task whatever it's successful or not; 2 parameters
Example:
// create a text document
$SP().createFile({
content:"Hello World!",
filename:"SubFolder/myfile.txt",
library:"Shared Document",
fields:{
"Title":"My Document",
"File_x0020_Description":"This is my file!"
},
after:function(fileURL, error) {
if (error) alert("Error: "+error)
else alert("File created at " + fileURL); // fileURL -> http://mysite/Shared Documents/SubFolder/myfile.txt
}
});
// you can remove "library" if you use $SP().list()
$SP().list("Shared Document").createFile({
content:"Hello World!",
filename:"SubFolder/myfile.txt",
fields:{
"Title":"My Document",
"File_x0020_Description":"This is my file!"
},
after:function(fileURL, error) {
if (error) alert("Error: "+error)
else alert("File created at " + fileURL); // fileURL -> http://mysite/Shared Documents/SubFolder/myfile.txt
}
})
// we can also create an Excel file
// a good way to export some data to Excel
$SP().createFile({
content:"<table><tr><th>Column A</th><th>Column B</th></tr><tr><td>Hello</td><td>World!</td></tr></table>",
filename:"myfile.xls",
library:"Excel Exports",
after:function(fileURL) {
window.location.href=fileURL;
}
});
// You can use https://github.com/Aymkdn/FileToDataURI if you want to be able to read a local file
// and then upload it to a document library, via Javascript/Flash
// We'll use "encoded:true" to say our content is already a base64 string
$SP().createFile({
content:"U2hhcmVwb2ludFBsdXMgUm9ja3Mh",
encoded:true,
filename:"Demo/HelloWorld.txt",
library:"Documents",
url:"http://my.other.site/website/"
});
// NOTE: in some cases the files are automatically checked out, so you have to use $SP().checkin()
A callback function that will be triggered after the task
Example:
// create a folder called "first" at the root of the Shared Documents library
// the result should be "http://mysite/Shared Documents/first/"
$SP().createFolder({
path:"first",
library:"Shared Documents",
url:"http://mysite/",
after:function() { alert("Folder created!"); }
});
// create a folder called "second" under "first"
// the result should be "http://mysite/Shared Documents/first/second/"
// if "first" doesn't exist then it will be created
$SP().createFolder({
path:"first/second",
library:"Shared Documents",
after:function() { alert("Folder created!"); }
});
// Note: To delete a folder you can use $SP().list().remove()
Find the User ID, work email, and preferred name for the specified username (this is useful because of the User ID that can then be used for filtering a list)
Parameters:
String
username
That must be "domain\\login" for Sharepoint 2010, or something like "i:0#.w|domain\\login" for Sharepoint 2013
Object
setupOptional
Options (see below)
String
setup.urlOptional, Default: 'current website'
The website url
Function
resultOptional
A function that will be executed at the end of the request with a param that is an object with the result ({ID,Sid,Name,LoginName,Email,Notes,IsSiteAdmin,IsDomainGroup,Flags}), or a String with the error message
Example:
$SP().getUserInfo("domain\\john_doe",{url:"http://my.si.te/subdir/"}, function(info) {
if (typeof info === "string") {
alert("Error:"+info); // there was a problem so we show it
} else
alert("User ID = "+info.ID)
});
Permits to notify the user using the SP.UI.Notify.addNotification system
Parameters:
String
message
Message to show
Object
optionsOptional
Integer
options.timeoutOptional, Default: 5
The number of seconds that the notification is shown
Boolean
options.overrideOptional, Default: false
This option to TRUE permits to remove the previous/current notification that is showing (even if the timeout is not over and even if it's a sticky) and replace it with the new one
Boolean
options.overrideAllOptional, Default: false
Same as previously except that it will remove *all* the previous notifications that are currently showing
Boolean
options.overrideStickyOptional, Default: true
When "overrideAll:true" then even the sticky notifications are removed, but you can block this behavior with "overrideSticky:false"
Boolean
options.stickyOptional, Default: false
Keep the notification on the screen until it's manually removed (or automatically removed with "overrideAll:true" and "overrideSticky:true")
String
options.nameOptional, Default: random()
You can give a name to the notification (to use it with $SP().removeNotify('name'))
You can call this function when the notification is removed -- the argument "name" is the name of the notification (see previous option), the argument "afterDelay" is TRUE when the notification has been removed by the system after it's normal timeout
Example:
$SP().notify('Processing the data...', {sticky:true}); // the notification will stay on the screen until we remove it
$SP().notify('All done!', {overrideAll:true}); // the "Processing the data..." is removed from the screen and a 5 seconds message says "All done!"
$SP().notify('Please wait 10 seconds...', {
name:"My 10 seconds notification",
timeout:10,
after:function(name,afterDelay) {
if (afterDelay) alert("OK, you waited during 10 seconds!")
else alert("Something just removed this notification called '"+name+"'' before the timeout :-(")
}
})
Use a WHERE sentence to transform it into a CAML Syntax sentence
Parameters:
String
where
The WHERE sentence to change
String
escapeCharOptional, Default: true
Determines if we want to escape the special chars that will cause an error (for example '&' will be automatically converted to '&')
Example:
$SP().parse('ContentType = "My Content Type" OR Description <> null AND Fiscal_x0020_Week >= 43 AND Result_x0020_Date < "2012-02-03"');
// -> return <And><And><Or><Eq><FieldRef Name="ContentType" /><Value Type="Text">My Content Type</Value></Eq><IsNotNull><FieldRef Name="Description" /></IsNotNull></Or><Geq><FieldRef Name="Fiscal_x0020_Week" /><Value Type="Number">43</Value></Geq></And><Lt><FieldRef Name="Result_x0020_Date" /><Value Type="DateTime">2012-02-03</Value></Lt></And>
// available operators :
// "<" : less than
// "<=" : less than or equal to
// ">" : greater than
// ">=" : greater than or equal to
// "<>" : different
// "~=" : this must be only used when comparing to a number that represents the User ID (e.g. 'User ~= 328') - that permits to query a list with too many items but with the User column that is indexed
// " AND "
// " OR "
// " LIKE " : for example 'Title LIKE "foo"' will return "foobar" "foo" "barfoobar" "barfoo" and so on
// " IN " : for example 'Location IN ["Los Angeles","San Francisco","New York"]', equivalent to 'Location = "Los Angeles" OR Location = "San Francisco" OR Location = "New York"' — SP2013 limits each IN to 60 items. If you want to check Lookup IDs instead of text you can use '~' followed by the ID, for example 'Location IN ["~23", "~26", "~30"]'
// special words:
// '[Me]' : for the current user
// '[Today]' : to use the today date
// '[Today+X]' : to use today + X days
// Null : for the Null value
// TRUE : for the Yes/No columns
// FALSE : for the Yes/No columns
// in the below example, on the "&" will be escaped
var bar="Bob & Marley";
var foo="O'Conney";
$SP().parse('Bar = "'+bar+'" AND Foo = "'+foo+'"'); // -> <And><Eq><FieldRef Name="Bar" /><Value Type="Text">Bob & Marley</Value></Eq><Eq><FieldRef Name="Foo" /><Value Type="Text">O'Conney</Value></Eq></And>
$SP().parse("Bar = '"+bar+"' AND Foo = '"+foo+"'"); // don't put the simple and double quotes this way because it'll cause an issue with O'Conney
Find the user details like manager, email, colleagues, ...
Parameters:
String
usernameOptional
With or without the domain, and you can also use an email address, and if you leave it empty it's the current user by default (if you use the domain, don't forget to use a double \ like "mydomain\\john_doe")
Object
setupOptional
Options (see below)
String
setup.urlOptional, Default: 'current website'
The website url
Function
resultOptional
A function that will be executed at the end of the request with a param that is an array with the result, or a String with the error message
Example:
$SP().people("john_doe",{url:"http://my.si.te/subdir/"}, function(people) {
if (typeof people === "string") {
alert(people); // there was a problem so we prompt it
} else
for (var i=0; i < people.length; i++) console.log(people[i]+" = "+people[people[i]]);
});
Provide the Date Format based on the user regional settings (YYYY for 4-digits Year, YY for 2-digits day, MM for 2-digits Month, M for 1-digit Month, DD for 2-digits day, D for 1-digit day) -- it's using the DatePicker iFrame (so an AJAX request)
Parameters:
Function
callbackOptional
It will pass the date format
Example:
// you'll typically need that info when parsing a date from a Date Picker field from a form
// we suppose here you're using momentjs
// eg. we want to verify start date is before end date
var startDate = $SP().formfields("Start Date").val();
var endDate = $SP().formfields("End Date").val();
$SP().regionalDateFormat(function(dateFormat) {
// if the user settings are on French, then dateFormat = "DD/MM/YYYY"
if (moment(startDate, dateFormat).isAfter(moment(endDate, dateFormat))) {
alert("StartDate must be before EndDate!")
}
})
// Here is also an example of how you can parse a string date
// -> https://gist.github.com/Aymkdn/b17903cf7786578300f04f50460ebe96
Find the region settings (of the current user) defined with _layouts/regionalsetng.aspx?Type=User (lcid, cultureInfo, timeZone, calendar, alternateCalendar, workWeek, timeFormat..)
Parameters:
Function
callbackOptional
A function with one paramater that contains the parameters returned from the server
Example:
$SP().regionalSettings(function(region) {
if (typeof region === "string") {
// something went wrong
console.log(region); // returns the error
} else {
// show the selected timezone, and the working days
console.log("timeZone: "+region.timeZone);
console.log("working days: "+region.workWeek.days.join(", "))
}
})
Permits to remove a notification that is shown on the screen
Parameters:
String
nameOptional
Name of the notification
Object
optionsOptional
If you pass the options, then the 'name' is ignored
Boolean
options.allOptional, Default: false
To TRUE to remove ALL notifications
Boolean
options.includeStickyOptional, Default: true
To FALSE if you don't want to remove the sticky notifications (only works with the "all:true" option)
Example:
$SP().notify('Processing the data...', {sticky:true,name:"Processing data"}); // the notification will stay on the screen until we remove it
$SP().removeNotify("Processing data"); // the notification is removed
$SP().notify('Doing some stuff...');
$SP().notify('Doing some other stuff...');
$SP().removeNotify({all:true}); // all the notifications are removed
$SP().notify('Doing some stuff...');
$SP().notify('Doing some other stuff...');
$SP().notify('This is a sticky message', {sticky:true});
$SP().removeNotify({all:true, includeSticky:false}); // all the notifications are removed except the sticky one
Show a modal dialog (based on SP.UI.ModalDialog.showModalDialog) but provides some advanced functions and better management of the modals (for example when you launch several modals)
Parameters:
Object
optionsOptional
Regular options from http://msdn.microsoft.com/en-us/library/office/ff410058%28v=office.14%29.aspx with some additional ones or some changes
String
options.htmlOptional
We can directly provide the HTML code as a string
String
options.widthOptional
If equals to "calculated", then we use the 2/3 of the viewport width; if equals to "full" then we use the full viewport width; otherwise see the original documentation (https://msdn.microsoft.com/en-us/library/office/ff410058(v=office.14).aspx)
String
options.heightOptional
If equals to "calculated", then we use 90% of the viewport height; if equals to "full" then we use the full viewport height; otherwise see the original documentation (https://msdn.microsoft.com/en-us/library/office/ff410058(v=office.14).aspx)
Boolean
options.closePreviousOptional, Default: false
It permits to close a previous modal dialog before opening this one
Boolean
options.waitOptional, Default: false
If we want to show a Wait Screen (alias for $SP().waitModalDialog())
String
options.idOptional, Default: random()
An unique ID to identify the modal dialog (don't use space or special characters)
Function
options.callbackOptional
A shortcut to `dialogReturnValueCallback` with dialogResult and returnValue
Function
options.onloadOptional
The modal might be delayed as we need to load some Sharepoint JS files; the `onload` function is called once the modal is shown
Function
options.onurlloadOptional
When we use the "url" parameter, this is triggered when the DOMContent of the iframe is loaded (if it's the same origin)
String
options.titleOptional
The title to give to the modal (if you use `wait:true` then it will be the main text that will appear)
String
options.messageOptional
This parameter is only use if there is `wait:true` and permits to define the subtitle message
String
options.urlOptional
A string that contains the URL of the page that appears in the dialog. If both url and html are specified, url takes precedence. Either url or html must be specified.
Number
options.xOptional
An integer value that specifies the x-offset of the dialog. This value works like the CSS left value.
Number
options.yOptional
An integer value that specifies the y-offset of the dialog. This value works like the CSS top value.
Boolean
options.allowMaximizeOptional
A Boolean value that specifies whether the dialog can be maximized. true if the Maximize button is shown; otherwise, false.
Boolean
options.showMaximizedOptional
A Boolean value that specifies whether the dialog opens in a maximized state. true the dialog opens maximized. Otherwise, the dialog is opened at the requested sized if specified; otherwise, the default size, if specified; otherwise, the autosized size.
Boolean
options.showCloseOptional, Default: true
A Boolean value that specifies whether the Close button appears on the dialog.
Boolean
options.autoSizeOptional
A Boolean value that specifies whether the dialog platform handles dialog sizing.
Example:
$SP().showModalDialog({
title:"Dialog",
html:'<h1>Hello World</h1><p><button type="button" onclick="$SP().closeModialDialog(\'here\')">Close</button></p>',
callback:function(dialogResult, returnValue) {
alert("Result="+dialogResult); // -> "here"
}
})
// show a waiting message
$SP().waitModalDialog("Working...");
// --- do some stuff ---
// close the waiting message and open a new modal dialog
$SP().showModalDialog({
closePrevious:true,
title:"Success",
html:'<h1>Done!</h1>'
})
// and use $SP().closeModalDialog() to close it