Tag Info

Hot answers tagged

54

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


23

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


20

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

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;


12

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


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


11

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


10

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


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

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


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


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

The Following code will Display all Libraries and Folders of each Library in Treeview private void frmForm1_Load(object sender, EventArgs e) { using (ClientContext clientcontext= new ClientContext("http://your server")) { //Load Libraries from SharePoint clientcontext.Load(clientcontext.Web.Lists); ...


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


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

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


8

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


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

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

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

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


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

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

I solved this by using a CamlQuery directly after creation to return folders with the same name as a ListItemCollection: SP.CamlQuery query = new SP.CamlQuery(); query.ViewXml = "<View Scope='RecursiveAll'>" + "<Query>" + "<Where>" + "<And>" + ...


7

AFAIK, it's only possible to use getByName in SharePoint 2013, not in 2010. See MSDN reference for more information var groupCollection = clientContext.get_web().get_siteGroups(); visitorsGroup = groupCollection.getByName("SomaGroupName");



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