Tag Info

Hot answers tagged

52

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


19

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


19

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


16

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


12

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;


11

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


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


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


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

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


9

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


8

Retrieving a lookup field is no different than retrieving any other field, but getting at the value takes an extra step. (using your example) var childIdField = oListItem["ChildId"] as FieldLookupValue; if (childIdField != null) { var childId_Value = childIdField.LookupValue; var childId_Id = childIdField.LookupId; } The reason for the extra ...


8

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


8

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


8

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


8

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


7

Unlike SP.UI.Status you have no direct way of setting the color with notifications, but since it is a simple HTML string you are adding you decide what goes into the notification area. I havent tested it, but the following syntax should be perferctly legal: SP.UI.Notify.addNotification('<span style=\'background-color:red\'>Operation ...


7

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()) { ...


7

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


7

This link might help you out: http://www.chaholl.com/archive/2010/11/17/using-the-dialog-framework-in-sharepoint-2010.aspx So according to this, you will have to do: var args = SP.UI.ModalDialog.get_childDialog().get_args(); on the NewForm.aspx page to access the values passed on that page.


7

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


7

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


6

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


6

You can use the ECMA Script Client Object Model: ExecuteOrDelayUntilScriptLoaded(loadWebs, "sp.js"); function loadWebs() { var clientContext = new SP.ClientContext.get_current(); this.webs = clientContext.get_web().get_webs(); clientContext.load(this.webs); clientContext.executeQueryAsync(Function.createDelegate(this, ...


6

You missed this line: clientContext.load(this.listFields); right after this.listFields = defaultview.get_viewFields(); , because your code not actually loads fields. Complete code with field type checking looks like this one: var clientContext = new SP.ClientContext.get_current(); var web = clientContext.get_web(); var list = ...


6

You should use SP.ListCollection.getEnumerator() method in order to enumerate lists, and SP.List.hidden property to check, whether the list is hidden or not. The corresponding code will look something like this: function GetHiddenLists() { var ctx = new SP.ClientContext.get_current(); var web = ctx.get_web(); var lists = web.get_lists(); ...


6

SharePoint 2010 introduces new feature named Script On Demand. It means that almost all scripts in sharepoint loaded on demand. In your situation you access to SP.ClientContext that is declared in sp.js, which is not loaded yet. Special function exists to wait until particular js file is loaded - ExecuteOrDelayUntilScriptLoaded. This function accepts two ...


6

Client Object Model have the limitations with regards to the way a List Item Update works. More specifically there is no SystemUpdate() type functionality available in Client Object Model, like in the 'full' SharePoint Object Model. If you really want to develop his functionality, then write your own custom web service that updates the document metadata ...


6

http://msdn.microsoft.com/en-us/library/ff458385.aspx: {SiteUrl} – The fully qualified URL to the site (Url). The SharePoint code proves it - here's the SPCustomActionElement.ReplaceUrlTokens method: internal static string ReplaceUrlTokens(string urlAction, SPWeb web, SPList list, SPListItem item) { if (string.IsNullOrEmpty(urlAction)) ...



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