Tag Info

Hot answers tagged

9

As a part of the new Minimal Download Strategy (MDS) the sp.js library is not loaded until explicitly called in SharePoint 2013. Your case is pretty common, for example for a publishing pages, where sp.js library is loaded in the edit mode but not in the display mode. Solution Prefer SP.SOD.executeFunc over SP.SOD.ExecuteOrDelayUntilScriptLoaded ...


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.


9

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


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

Use the MasterUrl and CustomMasterUrl properties of Web: using (var ctx = new ClientContext( url )) { var web = ctx.Web; var masterPageUrl = String.Format( "{0}/_catalogs/masterpage/oslo.master", ctx.Web.ServerRelativeUrl ); web.MasterUrl = masterPageUrl; web.CustomMasterUrl = masterPageUrl; web.Update(); ctx.Load( web ); ...


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

user1901384 is correct, ExecuteOrDelayUntilScriptLoaded won't load it, it will just check to see if it has been loaded. Take a look at this code sample (full page here). You don't need the clientContext part, what you're looking for is SP.SOD.executeFunc() but I left in the clientContext because you might find that helpful as well. Put your console.log('2') ...


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

what version of sharepoint you using ? .getByName() This is not in 2010 and was introduced in 2013. The only thing i know of in 2010 that uses getbyname is getting the web role definition. get_web().get_roleDefinitions().getByName("Read Only Access"); im sure there are other things that use it but what your looking for is only applicable in 2013 ...


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

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.


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


4

You need to use the overload for SPField.Update that takes a boolean parameter. That will push the changes to lists that use the field.. I.e., in Powershell: $myField.Update($true) MSDN documentation here.


4

Your example contains the following errors/typos: To get fs object type use the following syntax: var fsObjType = selectedItem.get_fileSystemObjectType(); Another point is, ListItem object have to be requested first before getting it's value, this is why in your example it will not work. In fact, you don't have to request ListItem object in order ...


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

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


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

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


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

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


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

CSOM Feature object exposes the following properties: DefinitionId - gets the GUID that identifies the Feature definition DisplayName - feature name Such SSOM Feature properties as SPFeature.Definition or SPFeature.Properties are not available in CSOM/REST. Below examples demonstrate how to manage features using CSOM Example: how to retrieve ...


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

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); ...


4

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


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



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