Tag Info

Hot answers tagged

13

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


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


7

Check out this blog post by Andrew Connell where he talks about using Breeze with SharePoint. With Breeze your code will look something more like: var promise = breeze.EntityQuery .from(contactType.defaultResourceName) .using(entityManager) .execute() .where('Id', 'eq', 1) .then(function (data) { return data.entity; }); // update the first ...


6

It actually depends on which version of SharePoint is used. SharePoint 2013 In SharePoint 2013 CSOM ListItem.Folder property gets a folder object that is associated with a folder item. SharePoint 2010 In SharePoint 2010 CSOM Folder property is not exposed for ListItem object. The following method could be used for retrieving Folder associated with ...


5

Place the second code section in a function and call it from the success function of the first passing the userid as a parameter.


5

For demonstration purposes, let's assume we have a custom list named Phones with the following fields: Title (manufacturer) Model According to Fiddler, the query: var fieldNames = new[] { "Title", "Model" }; foreach (var fieldName in fieldNames) { context.Load(items, includes => includes.Include(i => i[fieldName])); } ...


5

ExecuteOrDelayUntilScriptLoaded is a method used to delay a function call unless a particular script is loaded. Yes, you can use it in application page. If you are using CSOM you need to add a reference to sp.js file. You can also use SP.SOD.executeFunc if you are using on demand scripts. A very good article on this is here


5

Since SP.SOD.executeFunc supports on demand scripts, but SP.SOD.executeOrDelayUntilScriptLoaded does not, I would recommend to use SP.SOD.executeFunc with CSOM: SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() { var clientContext = SP.ClientContext.get_current(); console.log(clientContext.get_url()); });


4

SharePoint 2013 CSR OnPreRender handler could used for initialization of ClientContext since OnPreRender is called before the actual View/Fields rendering Example: (function () { function OnPreRenderDocItemTemplate(renderCtx) { SP.SOD.executeOrDelayUntilScriptLoaded(loadContext, 'sp.js'); function loadContext() { ...


4

AFAIK, using the existing services; it is not possible to access the content database informations from Client Object model or services. As a work around you can create your own WCF service and deploy it in SharePoint, which can provide your required data. How to Customize WCF Services in SharePoint 2010 SharePoint 2010: Create Custom WCF Service


4

When developing JavaScript apps against the SharePoint 2013 REST and CSOM APIs it is recommended to leverage Promises Patterns since it allows separate out the various asynchronous calls while still maintaining the dependency between them. There are several techniques for implementing promises, but one of the easiest is to make use of the jQuery $.Deferred ...


4

You need to use the overload for SPField.Update that takes a boolean parameter. That will push the changes to lists that use the field.. I.e., in Powershell: $myField.Update($true) MSDN documentation here.


4

You are missing the <View> tags in your ViewXml (see example here) It should be string qs = String.Format("<View><Query><Where><Eq><FieldRef Name=\"Title\"></FieldRef><Value Type=\"Text\">{0}</Value></Eq></Where></Query></View>", listItemTitle); query.ViewXml = qs; In case of ...


4

I normally follow as below SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction); function readyFunction() { getCurrUser(); evalGroups(); getDeptMgrs(); getItemOwner(); } Its more readable!


4

You Can set it by updating the Item with the choice value, as below newListItem["ChoiceFieldName"] = "ChoiceValue"; newListItem.Update(); clientContext.Load(newListItem); clientContext.ExecuteQuery(); But if you are assigning a Value which is not in the Choice Column, You need to create a choice value then assign it to the item.


4

Example 1 Explicitly specify choice value: using (var ctx = new ClientContext(webUri)) { var list = ctx.Web.Lists.GetByTitle("Tasks"); var taskItem = list.GetItemById(itemId); taskItem["Status"] = "In Progress"; taskItem.Update(); ctx.ExecuteQuery(); } Example 2 Choose a value from field choice: using (var ctx = new ...


3

In this approach it is determined whether User belongs to specific Group and if so, then he/she is getting redirected to another page: function isUserMemberOfGroup(userId, groupId, success,error) { var ctx = SP.ClientContext.get_current(); var allGroups = ctx.get_web().get_siteGroups(); var group = allGroups.getById(groupId); ...


3

How to retrieve UserInfo by UserName from UserInfo List via CSOM function getUserInfo(userName,Success,Error) { var context = new SP.ClientContext.get_current(); var userInfoList = context.get_web().get_siteUserInfoList(); var query = new SP.CamlQuery(); var viewXml = "<View> \ <Query> \ ...


3

How to create Folder (including nested) via CSOM in SharePoint /// <summary> /// Create Folder (including nested) client object /// </summary> /// <param name="web"></param> /// <param name="listTitle"></param> /// <param name="fullFolderPath"></param> /// <returns></returns> public static Folder ...


3

you can use this code to retrive the items from MSDN: // Starting with ClientContext, the constructor requires a URL to the // server running SharePoint. ClientContext context = new ClientContext("http:SiteUrl"); // Assume the web has a list named "Announcements". List announcementsList = context.Web.Lists.GetByTitle("Announcements"); // This creates ...


3

you can do CRUD operations using SPServices e.g - Create Items function CreateNewItem() { $().SPServices({ operation: "UpdateListItems", async: false, batchCmd: "New", listName: "Objectives", valuepairs: [["Title", "YourTitle"], ["Message=", "Message Text"]], completefunc: function(xData, Status) { alert("done"); } });} ...


3

The code that you've provided, works in my case. Probably the reason why it returns NULL is because property name that is passed does not exist.. The following code sample demonstrates how to retrieve custom field property value: function loadFieldsProperties(listTitle) { var clientContext = new SP.ClientContext(); var targetList = ...


3

This article has a very detailed inatruction how to use tests and fakes with SharePoint: http://msdn.microsoft.com/en-us/library/jj822928.aspx


3

Give this a try, function retrieveAllListProperties(siteUrl) { var clientContext = new SP.ClientContext(siteUrl); var oWebsite = clientContext.get_web(); this.collList = oWebsite.get_lists(); clientContext.load(collList); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), ...


3

How to remove field from List View via CSOM (JavaScript) function DeleteFieldFromListView(url,listTitle,fieldName,OnSuccess,OnError) { var context = new SP.ClientContext(url); var list = context.get_web().get_lists().getByTitle(listTitle); var view = list.get_defaultView(); var viewFields = view.get_viewFields(); ...


3

It actually depends what version of SharePoint is used. How to retrieve Variation Labels via CSOM? Since variations labels are stored in a Hidden List (MOSS 2007, SPS 2010/2013) we could retrieve it via CSOM (ECMAScript) as demonstrated below: function getVaritationLabels(OnSuccess,OnError){ var ctx = SP.ClientContext.get_current(); var rootWeb = ...


3

How to get current Folder client object via CSOM (JavaScript) function get_currentFolder(OnSuccess,OnError){ var context = SP.ClientContext.get_current(); var web = context.get_web(); var currentFolder = web.getFolderByServerRelativeUrl(decodeURIComponent(ctx.rootFolder)); context.load(currentFolder); context.executeQueryAsync( ...


3

It seems it occurs due to the naming conflicts for object termStores If to rename variable termStores to, let's say, termStoreColl, then everything is working just fine. The code below works properly: function getTermStores() { var context = SP.ClientContext.get_current(); var session = SP.Taxonomy.TaxonomySession.getTaxonomySession(context); ...


3

This is something that is not possible, however you may create a custom web services instead as a work around. This C# solution will be able to help you to build your web-services to get credentials, Retrieving Credentials from the SharePoint Secure Store using C#


3

With External lists the BDC Identity IS what you want you want in lieu of the traditional list item ID. This is actually in an MSDN reference that I am failing to find to provide a link too. I was still dealing with the problem of each BDC Identity being duplicates - which is why the getSelectedItems was not working. We resolved this by correcting the ...



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