Tag Info

Hot answers tagged

68

Looks like you're looking for MSOLayout_InDesignMode var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value; if (inDesignMode == "1") { // page is in edit mode } else { // page is in browse mode } This will refer to value of the following html input control, which is rendering on the page when it is in edit mode: ...


27

These techniques are silly. On every SharePoint page there's a javascript context variable: _spPageContextInfo { webServerRelativeUrl : "/ProjectWeb", webLanguage : 1033, currentLanguage : 1033, webUIVersion : 4, pageListId : "{c1d7b89f-f07b-4e2e-b89c-76c315831d59}", pageItemId : 5, userId : 68, alertsEnabled : true, ...


22

You can do it without any SharePoint calls by using the default JavaScript location object (W3schools) and the page variable _spPageContextInfo (Ted Pattison's Blog). Something like: var url = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;


21

Looks like nobody really came up with the right answer. There are a lot of answers here but I eventually found what I was looking for. Brage's answer is correct if I had a selection of items to work from. For this to work, you must enable item selection on the view and let the user select more than one item. SP.ListOperation.Selection will give you back a ...


17

You can use an function as a delegate and then call your function with in. ExecuteOrDelayUntilScriptLoaded(function () { alertThis("Hello World") }, "core.js"); function alertThis(value) { alert(value); } It is worth reading about closures, delegates and Anonymous functions in javascript to help understand the code. SO - How does an anonymous ...


14

How to check if current user belongs to SharePoint group via CSOM (JavaScript): function IsCurrentUserMemberOfGroup(groupName, OnComplete) { var currentContext = new SP.ClientContext.get_current(); var currentWeb = currentContext.get_web(); var currentUser = currentContext.get_web().get_currentUser(); ...


13

This could be done, but unfortunately only using two requests: first to retrieve view query text, second - to retrieve the items. function getItemsFromView(listTitle, viewTitle) { var context = new SP.ClientContext.get_current(); var list = context.get_web().get_lists().getByTitle(listTitle); var view = list.get_views().getByTitle(viewTitle); ...


13

Here is my fix to the problem. It seems in SP 2013 calling ExecuteOrDelayUntilScriptLoaded() doesnt work on published pages. In SP2013 this is the correct way to do it according to MS @ http://msdn.microsoft.com/en-us/library/jj245759.aspx // Make sure the SharePoint script file 'sp.js' is loaded before your // code runs. SP.SOD.executeFunc('sp.js', ...


12

You can do it like this: <script> function GetSiteUrl() { var ctx = new SP.ClientContext(); var site = ctx.get_site(); ctx.load(site); ctx.executeQueryAsync(function(s, a){alert(site.get_url())}); } </script> <a href='javascript:GetSiteUrl();'>Get site URL</a> To load only the URL from the site to minimize data ...


12

If you can you should use the Client Object Model (CSOM) - it does not support that many features as the web services but are superior in a number of ways such as: data types batching of commands (more efficient usage of bandwith) optimization of data loaded (more efficient usage of bandwidth) more similar to the server side object model in terms of ...


11

Looks like I just needed to add the get_lookupValue() function after my get_item call: alert(oDeptItem.get_item('Department').get_lookupValue()); Hope this helps someone...


11

You can get this from SP.FieldChoice.get_choices() (SPFieldChoice inherits SPFieldMultiChoice) To get that object you need to use context.castTo to cast SP.Field to SP.FieldChoice. // Setup context and load current web var context = new SP.ClientContext.get_current(); var web = context.get_web(); context.load(); // Get task list var taskList = ...


11

i managed to get it working . i changed the scope from "Recursive" to "RecursiveAll", RecursiveAll gets all files and all folders under the specidified location. Caml query was replaced with camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"> " + "<Query>" + "<Where>" + ...


10

A similar question was asked on StackOverflow some time ago (just found it). This answer provides the information you are searching. To provide a short version of the answer: strictly talking, the line "ULSrE8:;" does nothing (it does not execute the function) BUT the label is used by some intricate diagnostic/error logging code that parses the function ...


10

You load multiple items. A conflict occurs. Collect all items you need and call "load". After you call load for all items, then run context.executeQueryAsync. Save your selected items as a global variable (this.items): function showTitles(urlColumnName) { var context = new SP.ClientContext.get_current(); var web = context.get_web(); var lists = ...


10

According to How to set people and group column programmatically using Client Object Model this is how you set single user fields: SP.User _newUser = _ctx.Web.EnsureUser("domain\\username"); _ctx.Load(_newUser); _ctx.ExecuteQuery(); SP.FieldUserValue _userValue = new SP.FieldUserValue(); _userValue.LookupId = _newUser.Id; _listItem["userfield"] = ...


9

There is no equivalent. Per MSDN (suggested alternative at the end): The CSOM does not provide a mechanism for querying data across multiple lists that are not associated by a lookup field. In other words, there is no client-side functional equivalent of the SPSiteDataQuery class. If you need to perform a cross-list query from ...


9

Jquery approach can be implemented, but I'm afraid it will be exceedingly complicated, because ribbon buttons can change their size if you resize the browser window (so the id of the button will be changed respectively, for example from ..-Large to ..-Medium, etc.), and also they're created after page load, dynamically with js - so you will need some ...


9

You actually calling a web service when you use client object model according to this link. Of course use web service is more direct but i dont really care about performance penalty by using Client Object Model. The more concern is productivity improvement by using client object model. But if you more comfortable using web service, you can use it.


9

The reason why you get the SP.ClientContext is null or not an object error is because when you call your function on window.onload event, the sp.js file is not loaded on the page yet. The sp.js file contains all the code for the Client Object Model and hence your code is not able to find the SP.ClientContext object. The solution is pretty simple. Call you ...


9

It is more a caml question than an SPServices question. Often one uses or and and operators to combine multiple values, which, like @rjcp3 said, can be messy. There is another operator, less known, IN operator to choose a range of values (see the xml example below). To simplify the creation of CAML queries in javascript, I'd recommend SharePoint ...


9

Here you go: using (var context = new ClientContext("http://localhost")) { var allProperties = context.Web.AllProperties; allProperties["testing"] = "Hello there"; context.Web.Update(); context.ExecuteQuery(); }


9

I have used SharePoint’s JavaScript Object Model to retrieve the current logged in username.Once you have executed the load and executeQueryAsync methods and the call to SharePoint was sucessful, then inside of the onQuerySucceeded method is where I display the username to the browser using the SP.Principal.get_loginName property. Try it out…you can host ...


9

You cannot make cross-sitecollection calls from javascript client object model in SharePoint 2010. But you can make such calls in SharePoint 2013: var crossSiteContext = new SP.ClientContext("http://url-of-another-siteCollection/"); var crossSiteWeb = crossSiteContext.get_web(); crossSiteContext.load(crossSiteWeb); ...


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

There is also a global object available called 'PageState'. Among the various members of state information is "ViewModeIsEdit". If the value of this member is "1" then you are in edit mode (e.g. PageState.ViewModeIsEdit === "1"). Note: This variable is initialized after sp.ribbon.js gets loaded and is initialized from the _spBodyOnLoadFunctionNames array ...


8

SP.Ribbon.PageState.Handlers.isInEditMode() Returns true or false. I use this in publishing pages.


8

You can get the group collection of a site and enumerate over it to find a specific group. You can then enumerate the members of the group to find the current user. function onGetSharePointGroup() { var context = SP.ClientContext.get_current(); var groupsEnum = this.groupCollection.getEnumerator(); while (groupsEnum.moveNext()) { ...



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