Hot answers tagged client-object-model
38
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:
...
16
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 ...
14
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,
...
13
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 ...
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 ...
9
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;
8
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 ...
8
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 ...
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
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 ...
7
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.
7
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 = ...
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.
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
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 ...
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
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 ...
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))
...
6
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 ...
5
Since you're using the JavaScript CSOM you need to fetch the properties asynchronously. Your code should look something like this:
var oList;
function theFunction() {
var sListId = SP.ListOperation.Selection.getSelectedList();
var oWeb = item_clientContext.get_web();
oList = oWeb.get_lists().getById(sListId);
// .load() tells CSOM to load ...
5
As the MSDN documentation states, instance members of ClientContext are not guaranteed to be thread-safe:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.clientcontext.aspx
5
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);
...
5
Comparing execution in IE and in FireFox, I've found out that the problem is that a special "submenuRoot" attribute in IE is not set on the li element, which represents the "Send To" menu node.
After some painful debugging, I've tracked the issue back to method MergeAttributes in the core.js file. This method looks like this:
function ...
5
Why don't you step through it using the JS debugging tools available in most major browsers (IE, FF, Chrome). That combined with fiddler are the main tools I need to figure out weird things like this.
Off the top of my head, I would move the fadein, animate, and hover code into the onsuccess function at the end.
5
I had the same need and built my own jQuery widget... you can read more about it here:
http://paultavares.wordpress.com/2012/04/28/sharepoint-ui-widgets-upload-and-pickusers/
The zip file has a self-contained demo that demonstrate the use of the upload plugin. Make sure you have all the prerequisites in place.
Hope you find a good use for it.
Paul.
Only top voted, non community-wiki answers of a minimum length are eligible
