Tag Info

Hot answers tagged

14

This seems to be pretty close in performance: context.Load(lists, all => all .Where(l => l.RootFolder.Name == "MyListUrl") .Include(l => l.Id)); context.ExecuteQuery(); list = lists.Single(); If you need to get this by server-relative url you would need to parse the web url and list url first.


11

Yet another version to load List by server relative Url using CSOM. The solution consists of the following steps: Retrieve list Folder object using Web.GetFolderByServerRelativeUrl method Retrieve List by specifying List ID stored in vti_listname property from Folder.Properties object Code: static class WebExtensions { /// <summary> /// ...


7

For those who are still looking for the answer. SharePoint 2013 (since SP1 at least see UPD below) contains special method Web.GetList. It accepts site-relative url for the list, i.e. site/dev/lists/mylist. Sample code for .NET object model: var ctx = new ClientContext("http://sp2013dev/sites/dev"); var list = ...


7

You could also use _api/Web/Lists/GetByTitle('List title')/DefaultDisplayFormUrl If you want for all lists do _api/Web/Lists?$select=DefaultDisplayFormUrl Note that the property is not visible when visiting List directly, need full path or $select.


7

There are two ways to call executeQueryAsync in JSOM: context.executeQueryAsync( Function.createDelegate(this, _onSucceed), Function.createDelegate(this, _onFail) ); and context.executeQueryAsync(_onSucceed, _onFail); The difference between the two is the former allows you to override what the value of the "this" variable will be inside the ...


6

I normally follow as below SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction); function readyFunction() { getCurrUser(); evalGroups(); getDeptMgrs(); getItemOwner(); } Its more readable!


6

Farm Solutions (Full Trust): Develop for SharePoint On-Premises only. Can use managed code and the Server Object Model. This model has been around since SharePoint 2007 and is currently the most robust and well documented. Sandbox Solutions: Develop for SharePoint On-Premises or SharePoint Online. Can currently use managed code and a limited version of the ...


5

You can do it in Singleline of code var siteCollectionURL = _spPageContextInfo.siteAbsoluteUrl;


5

Example 1 Explicitly specify choice value: using (var ctx = new ClientContext(webUri)) { var list = ctx.Web.Lists.GetByTitle("Tasks"); var taskItem = list.GetItemById(itemId); taskItem["Status"] = "In Progress"; taskItem.Update(); ctx.ExecuteQuery(); } Example 2 Choose a value from field choice: using (var ctx = new ...


5

Since SP.ClientRuntimeContext.prototype.load(clientObject) method accepts properties as dynamic parameters, you could consider the following approach: var getList = function (listTitle) { var deferred = $.Deferred(); var ctx = SP.ClientContext.get_current(); var list = ctx.get_web().get_lists().getByTitle(listTitle); //construct ...


5

You are missing a couple of rows in a working script. First, after setting the oList variable you need to load it: clientContext.load(oList); Then you need to fetch the value by calling: clientContext.executeQueryAsync( Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed) ); Now, you need to create the ...


4

The following example demonstrates how to control field visibility in List Forms using JSOM function setFieldVisibility(listTitle,fieldName,properties,success,failure) { var ctx = SP.ClientContext.get_current(); var web = ctx.get_web(); var list = web.get_lists().getByTitle(listTitle); var field = ...


4

Use DefaultDisplayFormUrl at the time of loading the list in Javacript client object model. Example: var clientContext = new SP.ClientContext.get_current(); var list = clientContext.get_web().get_lists().getByTitle(listTitle); clientContext.load(list, 'DefaultDisplayFormUrl'); Then while enumerating the listitemcollection use get_defaultDisplayFormUrl() ...


4

Try giving "Read" permission to "Web" in AppManifest.xml and it should work.


4

You Can set it by updating the Item with the choice value, as below newListItem["ChoiceFieldName"] = "ChoiceValue"; newListItem.Update(); clientContext.Load(newListItem); clientContext.ExecuteQuery(); But if you are assigning a Value which is not in the Choice Column, You need to create a choice value then assign it to the item.


4

The CSOM (and the JSOM by extension) is a Microsoft generated collection of libraries that acts as a proxy to the server-side object model. You can see three different forms: .Net Silverlight Javascript In SharePoint 2013 it was greatly improved as it got additions for working with search, BCS, taxonomies, workflows and user profiles, and many more. You can ...


4

If you're dealing with a collection of items (example all of the items in a list, or all of the lists in a web), you need to use: clientContext.load(collOfItems, 'Include(Field1,Field2)'); For single items (like an individual site, list, or item) you need to use a comma seperated list of string arguments after the item to load, like: ...


4

You can leverage SP 2013 Search API s for this if you have a search configured and continous crawling enabled and there is huge number of sub sites to be iterated otherwise. //Raw code not tested , just to give idea of what it will look like function getSite(){ var clientContext = new SP.ClientContext("<serverRelativeUrl>"); var contextSite = ...


4

Apart from the explanation given by Amal, the reason you see error is var collListItem; is defined in getAllFilesInFolders function and the onQuerySucceeded method doesn't have its information unless you use this.collListItem which is passed during Function.createDelegate(this, this.onQuerySucceeded). Else you should define var collListItem; globally in ...


4

How to retrieve all web sites under a site collection using SharePoint JSOM The following function demonstrates how to recursively retrieve all sub sites: function getAllWebs(success,error) { var ctx = SP.ClientContext.get_current(); var web = ctx.get_site().get_rootWeb(); var result = []; var level = 0; var getAllWebsInner = ...


4

I would recommend the following example for loading web parts using JSOM: var ctx = new SP.ClientContext(); var pageFile = ctx.get_web().getFileByServerRelativeUrl(pageName); var webPartManager = pageFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared); var webPartDefs = webPartManager.get_webParts(); ...


4

You could consider the following modified example for enumerating all sites within site collection: function enumWebs(propertiesToRetrieve, success,error) { var ctx = SP.ClientContext.get_current(); var rootWeb = ctx.get_site().get_rootWeb(); var result = []; var level = 0; ctx.load(rootWeb,propertiesToRetrieve); result.push(rootWeb); ...


3

Here's a quicker way with SharePoint 2013: function CheckCurrentUserMembership() { var clientContext = new SP.ClientContext.get_current(); this.currentUser = clientContext.get_web().get_currentUser(); clientContext.load(this.currentUser); this.userGroups = this.currentUser.get_groups(); clientContext.load(this.userGroups); ...


3

First question : As far as I know this is the only way using the client model. I didn't understand your solution at first, so here is what I think is happening : adding UserRoleAssignements using UpdateDocumentSharingInfo with the options you chose will trigger a mail notification. If you set includeAnonymousLinksInNotification to True, the method will ...


3

In this approach it is determined whether User belongs to specific Group and if so, then he/she is getting redirected to another page: function isUserMemberOfGroup(userId, groupId, success,error) { var ctx = SP.ClientContext.get_current(); var allGroups = ctx.get_web().get_siteGroups(); var group = allGroups.getById(groupId); ...


3

Most probably it occurs since List.TemplateType and ListTemplateFeatureId properties for a out-of-the-box Custom List (Feature ID:00BFEA71-DE22-43B2-A848-C05709900100) are passed instead of your custom List. How to determine List TemplateFeatureId and TemplateType properties TemplateType:the list of available List template types could be found on this ...


3

SP.Folder.name property is read-only and hence it could not be used in update operation. How to rename Folder using SharePoint 2013 REST The following example demonstrates how to rename Folder using SharePoint 2013 REST API: function executeJson(url,method,additionalHeaders,payload) { var headers = {}; headers["Accept"] = ...


3

The operation of setting Enterprise Keywords field value consists of two steps: first one to resolve Keyword in Managed Metadata service application (MMS), this what EnsureKeyword method from below example is intended for After Keyword has been retrieved or created if it not existed, the value of Enterprise Keyword field is set to ...


3

If you don't want to use the GUID, you'll have to make an extra call and get the vti_listname property from the list folder. The folder you can get by url using the getFolderByServerRelativeUrl on the SP.Web object. Example: var clientContext = SP.ClientContext.get_current(); var web = clientContext.get_web(); var folder = ...


3

You could try the following method to determine whether a document set exists. How to find a Document Set via JSOM function getDocSet(listTitle,docSetName, success,error) { var context = SP.ClientContext.get_current(); var list = context.get_web().get_lists().getByTitle(listTitle); var items = list.getItems(createGetDocSetQuery(docSetName)); ...



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