Hot answers tagged

11

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


8

There is a property on the list for the default dispform, newform and editform url. Example: var clientContext = SP.ClientContext.get_current(); var list = clientContext.get_web().get_lists().getByTitle("ListTitle"); var caml = new SP.CamlQuery(); caml.set_viewXml("<View />"); var listItemCollection = list.getItems(caml); clientContext.load(list, ...


6

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


5

Using SharePoint 2010 JSOM i would suggest the following approach to retrieve list item attachments: determine whether List Item contains attachments or not via ListItem.Attachments property in case if list List Item contains attachments, submit a second request to retrieve attachment files Example function ...


5

Please see below code for getting all terms in a termset by using termsetid. The Key thing is making sure SP.js,sp.runtime.js and sp.taxonomy.js are loaded before you make a call to taxonomy store. $(document).ready(function () { //This makes sure all necessary Js files are loaded before you call taxonomy store ...


5

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


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


5

As stated in the comments, you would need to structure your code in a way to get the result of the asynchronous operation, your code should be something like this: SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getUserName); var user ; //declare this as a variable related to your current namespace, only here for demonstration. function getUserName(){ ...


4

Yes, you can add webparts using the client side object model. Summary: Use the LimitedWebPartManager defined for C# or JavaScript. Adding webparts is generally considered part of a provisioning solution and the OfficeDev Patterns and Practices (PnP) repository on GitHub has many examples that demonstrate different provisioning techniques. One specific ...


4

The method SaveAsTemplate is not exposed in CSOM API, there is a general suggestion opened: Expose List.SaveAsTemplate() for CSOM API Basically you can create lists using already existing custom templates, but programmatically you cannot create new ones. Site.GetCustomListTemplates(web); Web.ListTemplates What you can do is define the list schema xml and ...


4

Here is how to do it in JS var clientContext = SP.ClientContext.get_current(); var web = clientContext.get_web(); var webGroupsCollection = web.get_roleAssignments().get_groups(); //gets a web specificc groups var siteGroupsCollection = web.get_siteGroups(); //gets all site collections groups similarly there would be something like ...


4

I have corrected your code and here you go $(document).ready(function() { ExecuteOrDelayUntilScriptLoaded(GetDesc, "sp.js"); }); function GetDesc() { context = new SP.ClientContext.get_current(); web = context.get_web(); siteURL=$(location).attr('href'); var titleName=document.title; var mListName= "TestList"; ...


4

Some recommendations: 1) Avoid using global variables. Consider to pass parameters as function arguments, for example: function setLike(listId,itemId,like,success,error) { var ctx = SP.ClientContext.get_current(); Microsoft.Office.Server.ReputationModel.Reputation.setLike(ctx,listId,itemId, like); ctx.executeQueryAsync( function () { ...


4

In the newest release of the "SharePoint Online Management Shell" (v16.0.4630.1200) the included Microsoft.SharePoint.Client.dll adds the property RequestAccessEmail to the Web class. Download: https://www.microsoft.com/en-us/download/details.aspx?id=35588 You may use this DLL until the NuGet-Package is released.


3

You can look at the WebTemplate property of the Web object. The WebTemplate value will be "APP" if it is an App Web. // Exclude any App Webs if (subweb.WebTemplate.Equals("APP")) continue;


3

This is the implementation of SPWeb.IsAppWeb (via Reflector) public bool IsAppWeb { get { return (this.AppInstanceId != Guid.Empty); } }


3

One thing you can do is use SP.List.getItems(query) to query the 'Department' list for the item with the Title value you want. Once you get the list item, you can get its ID. (Keep in mind that the getItems(query) method will return a list item collection, even though that collection may only contain one item.) Your CAML query would look something like ...


3

Based on your question, i understand that you want to get ID of Department item which is referenced in Article list. Correct me if i am wrong. To get ID of lookup list item, include following in you code(Assuming field name of lookup field from Department is "Department" in article list : var childIdField = listItem["Department"] as FieldLookupValue; if ...


3

The following example demonstrates how to return web sites sorted by last modified date: function getWebs(success,error) { var ctx = SP.ClientContext.get_current(); var web = ctx.get_web(); var webs = web.getSubwebsForCurrentUser(null); ctx.load(webs); ctx.executeQueryAsync( function(){ var result = []; ...


3

Use Microsoft.SharePoint.Client.UserProfiles.PeopleManager.SetMultiValuedProfileProperty method to set multi-value user profile property, for example: using (var ctx = GetSPOContext(webUri,userName,password)) { PeopleManager peopleManager = new PeopleManager(ctx); var skills = new List<string>() { ...


3

I've used quite some time to get around a similar issue in regards to the Search API. Over and over again I was troubled with the following error-message: "Object doesn't support this action" Try to add a reference/key to "Microsoft.SharePoint.Client.Search.Query.KeywordQuery" instead of "Microsoft.SharePoint.Client.Search.Query". At least that worked for ...


3

You can use JavaScript call backs or Promises/deferreds to work synchronously with JavaScript client object model. CallBack Example: $(document).ready(function () { //don't exectute any jsom until sp.js file has loaded. SP.SOD.executeFunc('sp.js', 'SP.ClientContext', prepareTables); }); function prepareTables() { ...


3

The reason this is happening is because of the asynchronous nature of Javascript client object model. The statement after the function does not wait for the function to complete. In order to avoid this you can use deferreds/promises. UPDATE Callback Example of your code: myCallerFunction('abc', function (terms) { var termEnumerator = ...


3

I am using below code for past year or so SP.SOD.executeOrDelayUntilScriptLoaded(Function.createDelegate(this, function() { 'use strict'; var taxonomySodLoaded = false; if (typeof(_v_dictSod) !== 'undefined' && _v_dictSod['sp.taxonomy.js'] == null) { SP.SOD.registerSod('sp.taxonomy.js', ...


3

You need to return the promise in the itemIsDuplicate() function, not the success callback. Just move return deferred.promise(); to the end of the function. You'll might want to either add deferred.resolve() to the error callback, or a deferred.reject() if you need to execute something after an error occurs. Code should be as such: function ...


3

Map SharePoint library/site as a Network Drive. Now use Windows Explorer to browse file and open with your favourite editor. From my knowledge only SharePoint Designer Gives you a tree view navigation which we can use to browse the files and edit/save. Update You can use some registry tweak so that you can open files using your favourite editor from ...


3

Most probably the error File not found occurs since you are trying to retrieve attachments folder that not yet exist in method HasListItemAttachment The following example demonstrates how to upload attachment file via SharePoint JSOM: function processUpload(fileInput, listTitle, itemId,success,error) { var reader = new FileReader(); reader.onload = ...


3

You can check the Template type of a web object. If it is APP#0 you don't need to add it to List. The example here shows how to get the web template. http://stackoverflow.com/questions/19382310/using-client-object-model-how-to-fetch-the-web-template-name-and-web-templat


3

JavaScript Object Model code which you have used, is asynchronous. Which means the execution is passed on to next statement and HTML is rendered without waiting for the result you get in your variable appendingCssStyle. I doubt you will be able to achieve it with your existing code. Possible solutions Instead of assigning appendingCssStyle in HTML, You ...


2

You can save a site as a template (through Site Settings GUI). When create sites using this templates with different name etc. Instruction how to save site http://www.learningsharepoint.com/2012/11/23/how-to-save-site-as-template-in-sharepoint-2013/ Here http://get-spscripts.com/2011/02/finding-site-template-names-and-ids-in.html and Programmatically ...



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