Hot answers tagged

20 votes
Accepted

How to check whether the current user has edit permission for a particular list using JSOM in SharePoint 2013

You can try using below code. Since its OnPrem, we first need to get the login name of user and pass it to the get_effectiveBasePermissions method. To ensure that user has edit permission, we will ...
  • 30.5k
13 votes
Accepted

Get Parent web of a subsite using JSOM in SharePoint 2013

Using your SP.Web object, you can get the parent information (SP.WebInformation). Using its ID, you can then, via the site collection, get the parent web object. var context = new SP.ClientContext....
  • 1,480
12 votes

Using jQuery $(document).ready() in JavaScript Object Model

Document ready event gets fired when the DOM get loaded. This doesn't necessarily guarantee that the JS files required for SharePoint JSOM is already loaded. The best way is SP.SOD.executeFunc('sp....
  • 28.2k
12 votes
Accepted

Which one is faster CSOM or JSOM

Check out this excellent article where the performance of both is tested: Deep Dive – REST and CSOM Comparison I tested a series of pretty common operations in both REST and CSOM: Creating ...
  • 3,236
12 votes
Accepted

How to get List name by its GUID using Javascript

You can use the below rest call as well.: Replace guid with your list guid. $.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists(guid 'b778bbec-dd69-4a6c-9437-c73972c36292')", ...
  • 30.5k
11 votes
Accepted

How to get the current list/library name using JSOM?

Use ctx to get current list/library info. For Name or Title, It is ctx.ListTitle PS: No callback needed Following information can be retrieved from ctx about current list/library in SharePoint 2010....
11 votes
Accepted

'ctx' variable in SharePoint

ctx is a global variable. It belongs in the list view pages. var ctx = SP.ClientContext.get_current(); So if you use above line in any list view pages, it will cause an issue. The value of ctx will ...
11 votes

How to get List name by its GUID using Javascript

Using Client Object Model will help in this case: var oList; function getListTitleById() { var clientContext = SP.ClientContext.get_current(); oList = clientContext.get_web().get_lists()....
10 votes
Accepted

Get current user id in JSOM on sharepoint online

Can you not use _spPageContextInfo? It has the current user ID built in: _spPageContextInfo.userId https://social.technet.microsoft.com/wiki/contents/articles/29766.sharepoint-understanding-the-...
  • 12.3k
9 votes

How to check whether the current user has edit permission for a particular list using JSOM in SharePoint 2013

Here is the code you are looking for: var ctx = new SP.ClientContext.get_current(); var web = context.get_web(); var ob = new SP.BasePermissions(); ob.set(SP.PermissionKind.manageWeb) ob.set(SP....
8 votes
Accepted

Caml Query to return items created by logged in user

var context = new SP.ClientContext.get_current(); var list = context.get_web().get_lists().getByTitle("ListName"); var cQuery = new SP.CamlQuery(); var camlXML = "<View&...
  • 1,793
8 votes

create custom permission level in SharePoint Site programatically in JSOM or CSOM

CSOM For O365 This creates a permission level inherited from the Full Control level, and can be changed to your desirable permission level. namespace Console.Office365 { using Microsoft....
  • 5,239
7 votes

JSOM for anonymous users

One very common workaround I see is that you use an authenticated user to pull the Request that you need, then write it to a document library that allows anonymous access. Because most SP does not ...
  • 986
7 votes

Caml Query to return items created by logged in user

The Author column is of LookUp Type. Here is the complete list. var ctx = new SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle("Vacation Replacement"); var query = new ...
  • 1,718
7 votes
Accepted

Get SharePoint list items from another site collection with JSOM

To access information in the host web using the Javascript Object Model you need to use an SP.AppContextSite object in conjunction with your SP.ClientContext I see you're using TypeScript, which is ...
  • 5,880
7 votes
Accepted

Programmatically create workflow with JavaScript, JSOM and SP.WorkflowServices.WorkflowServicesManager

You need to load Id of the definition before creating subscription. Also subscriptionService.publishSubscriptionForList needs guid object instead of just GUID string. When we create List workflow ...
7 votes
Accepted

how to get a list's add new item URL with JSOM?

Load DefaultNewFormUrl property of the list. Example: clientContext.load(list, 'DefaultNewFormUrl'); Then retrieve it in the success method: var newUrl = list.get_defaultNewFormUrl();
7 votes
Accepted

How to get and set custom 'Web' properties in SharePoint online using javascript

You can read/write to web property bag using JavaScript object model. Example of reading the custom property: //wait until client object model dependencies are loaded before executing our code ...
7 votes

Display SharePoint list Hyperlink column Value Using JSOM

Hyperlink is a object. You can get its property by following For description listItem.get_item("{column internal name}").get_description() For Url listItem.get_item("{column internal name}")....
7 votes
Accepted

how to change the default gear icon look in SharePoint 2013?

You can change the icon using the following small jQuery code $( document).ready(function() { $('.ms-siteactions-imgspan > img').attr('src','url_Of_your_image'); });
7 votes
Accepted

SharePoint hosted-add in save date object in list

The problem is that you are using the method getDay(). That method will give you the day of the week in this case 3. You should be using the method getDate(). var dt = new Date(dtTest.getFullYear(), ...
7 votes
Accepted

How to pull data from root level site and display in subsite using JSOM?

Get the root site url as shown below: var siteUrl = _spPageContextInfo.siteAbsoluteUrl; Get client context using that url as shown below: var context = new SP.ClientContext(siteUrl); list = context....
7 votes

How to resolve "The property or field 'ListItemCollectionPosition' has not been initialized.." error?

You can include it like below. clientContext.Load(listItems,items => items.Include(item => item.Id), items => items.ListItemCollectionPosition);
7 votes

How can I get count of similar items records from list in SharePoint hosted app?

If I am not wrong, you want to group the list item with the column ids as displayed in the below image: In order to achieve this, please follow the following link: https://piyushksingh.com/2016/11/21/...
  • 1,735
6 votes
Accepted

SP2013 javascript client object model - get server time

Yes you should get the site's TimeZone first and then convert your DateTime accordingly. function getTimeZoneAndServerDateTime() { var context = SP.ClientContext.get_current(); var web = ...
  • 5,953
6 votes
Accepted

get_fieldValuesAsText usage example

Here is an example: var clientContext = SP.ClientContext.get_current(); var list = clientContext.get_web().get_lists().getByTitle("Title"); var item = list.getItemById(id); var fieldValuesAsText = ...
6 votes

Get Parent web of a subsite using JSOM in SharePoint 2013

An alternative to using the get_parentWeb is using the _spPageContextInfo object for urls and only needs one execute: if(_spPageContextInfo.siteServerRelativeUrl != _spPageContextInfo....
  • 6,238
6 votes

Zip document library using JSzip

You could consider the following solution: retrieve files collection via SharePoint JSOM API utilize getBinaryContent(path, callback) from JSZipUtils to load file content by file url generate zip ...
6 votes
Accepted

JSOM : run work flow using Javascript

You seem to pass 3 parameters to you method, that only expects 2, and seem to have mixed up the order of them. function startWorkflow(itemID, subID) So you should first pass the itemID, the integet ...
6 votes

How to pull data from root level site and display in subsite using JSOM?

This could help var context = new SP.ClientContext.get_current(); var web = context.get_web(); var parentInfo = web.get_parentWeb(); var parentWeb = context....

Only top scored, non community-wiki answers of a minimum length are eligible