Tag Info

Hot answers tagged

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> /// ...


9

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.


8

How to create Variation Labels in SharePoint 2013/Online via CSOM SharePoint 2010/2013 CSOM API does not expose any specific methods for creating Variation Labels, but you could use the following class for that purpose. VariationsClient class is intended for managing Variation Labels in SharePoint 2013. The following operations are currently supported: ...


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

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 = ...


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

You are missing the <View> tags in your ViewXml (see example here) It should be string qs = String.Format("<View><Query><Where><Eq><FieldRef Name=\"Title\"></FieldRef><Value Type=\"Text\">{0}</Value></Eq></Where></Query></View>", listItemTitle); query.ViewXml = qs; In case of ...


5

Depending whether taxonomy field is single-valued or or multi-valued use the corresponding method: single-valued taxonomy field: SP.Taxonomy.TaxonomyField.setFieldValueByValue by specifying SP.Taxonomy.TaxonomyFieldValue object multi-valued taxonomy field: SP.Taxonomy.TaxonomyField.setFieldValueByValueCollection Method by specifying ...


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

I know in the JavaScript Client Object Model executeQueryAsync is performed using an XmlHttpRequest, the results of which are cached by default. I would assume the managed client object model requests data using the same method 'under the covers' As for how long the cached request is valid, it appears to be dependent upon the user's browser configuration. ...


4

As an introductory please follow How to: Complete basic operations using SharePoint 2013 client library code article to get acquainted with how to update a SharePoint list item via CSOM. How to update list items via CSOM in PowerShell Assume the following data is contained in CSV file ID,FullName,Company,Title 1,Pilar Ackerman,Contoso Ltd,Manager ...


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

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

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

Referring directly the AssetPortalBrowser.aspx and getting the URL will be very much difficult, rather create an object and open the popup will be easier. Follow the below steps. I am getting the selected selected file in a text box and showing it in a alert. Go to Site Content > Site Assets Create a folder name Scripts Upload jquery-1.11.1.min.js and ...


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

Our company contacted Microsoft, and this is by design. For security reasons you cannot set the permissions of an app by client side code



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