Questions tagged [javascript]
Javascript is a dynamic computer programming language, most commonly used as part of web browsers, whose implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed.
5,367
questions
98
votes
13
answers
55k
views
How do I know if the page is in Edit Mode from JavaScript?
Is there a way to find out if a page is in Edit Mode from JavaScript?
I know server-side can be found using SPContext.Current.FormContext.FormMode but I can't find any means of doing it from ...
58
votes
7
answers
57k
views
How do you get the current list item in JavaScript?
There's all kinds of ECMAScript class library examples around but all of the ones I find show how to retrieve all list items (through SP.ClientContent) but how do you get the current list item? I'm ...
40
votes
4
answers
69k
views
SP.SOD how to use correctly?
SP.SOD is a nice feature of SharePoint, but how should I use it? For example, I use these lines of code
ExecuteOrDelayUntilScriptLoaded(function () {
//code
}, "custom.js");
If I understand ...
36
votes
6
answers
170k
views
REST API filter by start and end dates using 'today'
I'm new to filtering dates with REST in SP but am trying to do something like below but am not sure how to get today's date in as a variable into the request. I don't think I'm too far off so any help ...
30
votes
5
answers
48k
views
SP.UI.ModalDialog.showModalDialog using the html option
http://msdn.microsoft.com/en-us/library/ff410058.aspx says that you can use the option html to display html text in a modal.
I have a string like this;
var html = '<div><strong>Test</...
29
votes
5
answers
71k
views
Check if user is in a specified group
I would like to check with JavaScript if the current logged user is in a specified and specific group (for example called "Admins Group").
How can I do?
Thanks
26
votes
6
answers
45k
views
Send E-mail from javascript using REST API
I want to send email using Javascript/jQuery using REST API in SharePoint.
I have tried _api/SP.Utilities.Utility.SendEmail and this is my code:
Code
$.ajax({
contentType: 'application/...
25
votes
5
answers
119k
views
Get current user in Client Object Model with javascript?
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
alert(user);
I used above code to get the current user using JavaScript, but I ...
25
votes
4
answers
3k
views
Will the new SharePoint FrameWork increase speed?
I don't have a benchmark but it seems to me SharePoint Online is getting slower.
This is a fresh new SPOnline Tenant, (News) images being pulled from a Picture Library
Is it me or is this just super ...
24
votes
11
answers
96k
views
Get Site Collection full URL using javascript
I want to get the URL for my site collection. One way I thought I could do it was using the window.location in javascript and getting it that way.
I know that you can use ECMA script and the client ...
24
votes
3
answers
90k
views
Adding new list item using REST
I am currently using Office 365 and lots of REST queries to display data. However I am now creating my own forms using Bootstrap and jQuery.
However, how do I use REST to add the data to the list?
...
22
votes
5
answers
30k
views
How to avoid caching issue when using custom JavaScript and CSS deployed under _layouts?
On our farm, I'm deploying some JavaScript and CSS files under the _layouts folder.
I'm then referencing them, where it's required using a <SharePoint:ScriptLink> or a <SharePoint:...
22
votes
10
answers
30k
views
How can I disable the Document Library drag and drop function?
Before I start - I'm new to this SharePoint development lark and am slowly familiarising myself with it.
We're using SharePoint online and I have amended the SharePoint out-of-the-box document ...
20
votes
2
answers
62k
views
ExecuteOrDelayUntilScriptLoaded with sp.js when in debug mode Object Expected
I currently have a JavaScript file that gets loaded in my SharePoint pages.
jQuery(document).ready(function() {
ExecuteOrDelayUntilScriptLoaded(myfunction(), "sp.js");
});
myfunction = function(){
...
20
votes
3
answers
42k
views
How to get all items in a View using Client Object Model (JavaScript)
To get all the items in a List you use
// Setup context & load web
context = new SP.ClientContext.get_current();
web = context.get_web();
context.load(web);
// Load task list
this.List = web....
20
votes
6
answers
25k
views
How do I trigger the default form validation without submitting the form
I'm customizing the NewForm of a list item and need to trigger the default form validation from my JavaScript, but I don't want the form to be submitted, since I'm doing that in a callback later on.
...
19
votes
4
answers
18k
views
Changing date format using javascript
I am getting date in 2015-10-30T05:00:00Z format from a SharePoint list using rest.
Please help me to get the date in 2015-10-30 format using JavaScript.
19
votes
2
answers
28k
views
SharePoint 2013 REST - Create list item with user field and lookup field
I'm trying to add an SPListItem to an SPList via REST, but have a problem with User or Group and Lookup (information already on this site).
function adddullitem() {
var item = {
"...
19
votes
3
answers
6k
views
set column order of fields using CSOM/REST javascript
I am creting list fields using CSOM ecma script. How do I set the column order of the fields to be displayed in the form programmatically?
For eg: I have created the following fields programmatically :...
19
votes
4
answers
13k
views
Grab a specific property bag using ECMA script
I am trying to grab a key/value pair from a specific property bag but can't find any documentation or example code on how to grab a property bag. Currently I can only seem to grab allProperties. Here ...
18
votes
5
answers
54k
views
ExecuteOrDelayUntilScriptLoaded not executing after page publish
In SharePoint 2013 I have a page that is using the Script Editor web part.
In the script editor web part I have the following:
ExecuteOrDelayUntilScriptLoaded(startIt, "sp.js");
function startIt() {
...
18
votes
2
answers
17k
views
How to get a list of all Choice field options using Client Object Model
How would you get a list of all the possible choices from a choice field (e.g. Task list Priority or Status fields) using javascript client object model?
18
votes
1
answer
7k
views
What does this code getQueryStringParameter do?
I would like to know what this code does?
I am using it almost all the time but I don't know what it does.
function getQueryStringParameter(paramToRetrieve) {
var params =
document.URL.split("?")[1]....
18
votes
3
answers
27k
views
JavaScript: How to reuse the "Working on it..." pop in
Sharepoint 2013: In have custom JavaScript code that makes Ajax calls. While loading I'd like to show Sharepoint's loading pop in:
That is the one that greys out the underlying page and centers a ...
18
votes
1
answer
8k
views
Wait async query in PreSaveAction
Could you tell me, please, how can I wait for an async query to SharePoint list in PreSaveAction()?
Is it possible?
Thanks in advance!
18
votes
2
answers
9k
views
SP.Utilities.Utility.SendEmail with additional headers [javascript]
Want to use the built in SendEmail with javascript and jquery. Found this code and got it working -- sends the email -- using the code below:
var appweburl = "https://example.com/site";
var ...
18
votes
5
answers
33k
views
How can I use the SharePoint Javascript Object Model from a plain HTML page?
I would like to use the SharePoint Javascript Object Model from a "plain" html page (ie, not an .aspx application page etc.) Is this even possible? If so, what scripts should I reference? I've added ...
17
votes
4
answers
20k
views
Get the current UI language with ECMAScript
Is it possible to get the display language from within ECMAScript?
Similar to Get the current UI language from a webpart, I'd like to get the user's display language, however I want to access it with ...
17
votes
2
answers
72k
views
Order by Rest API in SharePoint 2013
var restURLAuthors = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('GoGreenReport')/items?$select=EncodedAbsUrl,FileRef&$filter=Project_x0020_Name eq '"+$("#ddnProjectName").val()...
17
votes
6
answers
7k
views
"a is null" error in vanilla SP2010 install
I'm setting up an SP2010 VM for dev testing purposes. Our vanilla install has no other components present and is throwing JS errors in Chrome and Firefox.
In Firefox (v13):
a is null
http://...
17
votes
2
answers
3k
views
Cannot add custom web part to page using the JS OM
I'm trying to add a custom web part (that is one I have written myself) using the new Javascipt OM available with SharePoint 2010. My solution is also running within the Sandbox.
I have it working ...
17
votes
0
answers
271
views
Replacing SOD with fetch (handling JS library dependencies - *in the future*)
Anticipating a future, I am experimenting with User Custom Actions in the new Document Library View Microsoft has so kindly provided to the First Release Office365 tenants.
Since there is almost ...
16
votes
5
answers
83k
views
How to get current user with javascript?
I have a list . I want select items of list with a special quary.(get items that created with current user). Then get count of items.
I use this code for get current user :
function Initialize()
{
...
16
votes
5
answers
4k
views
Can I tell what version of SharePoint is being used from JavaScript?
I have some static JavaScript being rendered to a page and would like it to behave differently if the version of SharePoint it is being displayed by is 2013. Can I tell what version of SharePoint is ...
16
votes
4
answers
11k
views
Basic batched GET requests using REST API
I'm hunting around on the web right now for some basic (preferably working) examples of making a batch of GET requests using the new $batch endpoint in O365 with the REST API.
I've located some good ...
16
votes
8
answers
21k
views
How do I determine a user's SharePoint group membership using the client object model?
I want to redirect users from a landing page to another page in SharePoint 2010, based on their group membership. I need to do this using JavaScript (ECMAScript) and not server side code.
16
votes
2
answers
32k
views
How to get all properties of all users in SharePoint 2013 Rest API?
I am using this code to get all properties for just myself (current user). But how can I change this so that I can get the same data but for all the users in SharePoint?
var oldurl = ...
16
votes
1
answer
5k
views
Change Sharepoint language with a link?
Is there a way to get the language-switch control as static link in the pagelayout?
I want my users to switch between German and English with a single click.
Sorry guys, found a solution :D
<...
15
votes
4
answers
16k
views
How to log off user from SharePoint site, if the user has been inactive for 20 minutes
How to log off the SharePoint site, if the user is has been inactive for for 20 minutes? Do I need to redirect user to logout page? How would I count the idle time?
15
votes
3
answers
35k
views
Difference in clientcontext.load() and clientcontext.executeQueryAsync() in javascript for SP
Please tell me the working of Load() and executeQueryAsync() in javascript for sharepoint 2013 i.e why we have to call Load() method when we have to call executeQueryAsync() .
15
votes
3
answers
4k
views
color code in SharePoint calendar
I have SharePoint calendar and I want the entries to be in color based on status.
If user add one entry and status is initially pending then that task would be in green, later it get changed to in ...
15
votes
2
answers
3k
views
Which one is faster CSOM or JSOM
Understanding which one has better performance for performing CRUD operation in SharePoint List, CSOM or JSOM?
15
votes
3
answers
3k
views
How to access a custom field of a list using REST
I'm trying to get information from a list in a custom SPField called "My Field" with the internal name "MyField" using this JavaScript code:
$.ajax({
url: "http://<URL>/_api/web/lists/...
14
votes
7
answers
39k
views
Enforce Drag and Drop documents to apply metadata
We have implemented an issue management system in SharePoint 2013 which provisions a page for every issue added to a specific list.
One of the Web Parts the automatically provisioned page contains ...
14
votes
2
answers
15k
views
Programmatically add JS/CSS to pages
I've created a Visual Studio SharePoint 2010 solution with an ASCX that adds some JavaScript files and CSS to the head of each page; this is based on this article. When I deploy the solution, it adds ...
14
votes
9
answers
73k
views
Getting a count of list items in a list via ECMAScript
I have a SharePoint 2010 web site with a master page that has a counter on it. I'm trying to update that counter using the ECMAScript. The code I have falls nicely into the success method - but I ...
14
votes
2
answers
28k
views
When to use scriptlink, scriptblock and script
I have seen an application page where the developer using scriptlink, and below that just , I was wondering when would each one be used?
14
votes
2
answers
11k
views
(Solved) Start a Workflow of the Host-Web via SharePoint App and JSOM
The Last Update is the Solution
I have got an App for SharePoint 2013, which needs to start a Workflow. This Workflow is in the HostWebContext, not in the AppContext. The List, the Workflow is ...
13
votes
6
answers
60k
views
What is the proper way to add custom CSS/JavaScript SharePoint 2013 site?
I would like to tweak the default layout in SharePoint, e.g. add...
.ms-number {
white-space: nowrap;
}
... to all pages.
I know it is possible to modify a master page directly, but is it the ...
13
votes
2
answers
27k
views
How to return a value using context.executeQueryAsync?
How can I get this function to return the value? In all the examples I have seen, folks use an alert in the delegate functions, but I need to return the value instead. When I call the function, it ...