Tag Info

Hot answers tagged

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

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


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


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


5

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

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

I know in the JavaScript Client Object Model executeQueryAsync is performed using an XmlHttpRequest, the results of which are cached by default. I would assume the managed client object model requests data using the same method 'under the covers' As for how long the cached request is valid, it appears to be dependent upon the user's browser configuration. ...


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

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

If this is an app or anything outside of a SharePoint page you need to load document.write('<script src="' + spHostUrl + '/_layouts/15/MicrosoftAjax.js"><\/script>') document.write('<script src="' + spHostUrl + '/_layouts/15/sp.runtime.js"><\/script>') document.write('<script src="' + spHostUrl + ...


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


3

string siteUrl = "your site url"; string sourceDirectory = "your source folder"; string destinationDirectory = "/Shared documents/West"; using (SPSite currSite = new SPSite(siteUrl)) { using (SPWeb currWeb = currSite.OpenWeb()) { MoveFolder(currWeb, sourceDirectory, destinationDirectory); } } ...


3

You can access the members of an enumeration (or any JavaScript object for that matter) using the C# indexer syntax. So the code you want would be something like: var typeList = SP.ListTemplateType["announcements"]; listCreationInfo.set_templateType(typeList); You can use a for loop to iterate all of the property values of the enumeration. var message = ...


3

using moment.js $(document).ready(function(){ var d = new Date("Tue June 24 09:30:07 PDT 2014"); $("#dDate").html(moment(d).format("DD/MM/YYYY")); }); it is been answered in this post: Format Date (25 Jul) using Javascript Object Model


3

Pros A wide range of SharePoint functionality is exposed with the SOAP Web Services, much of which is not available in CSOM Allows anonymous access (assuming it is enabled for the underlying objects) Works cross-site and cross-domain, assuming that the authentication model you are using allows it Simpler syntax than the CSOM. Simply pass the required ...


3

It basically depends on your personal experience with the different technologies, there are many opinions out there with lots of pros and cons that may or may not be relevant to you. I personally very much dislike pure javascript CSOM because of all the context loading and SPServices was a good abstraction for that, but eversince I've used REST in SP2013 I ...


3

You need to authenticate with your SPO credentials: var creds = new SharePointOnlineCredentials("user@tenant.onmicrosoft.com", password); // Requires SecureString() for password context.Credentials = creds; It needs to be done prior to your first context.ExecuteQuery(). Here is info on the SharePointOnlineCredentials class.


3

Depending whether taxonomy field is single-valued or or multi-valued use the corresponding method: single-valued taxonomy field: SP.Taxonomy.TaxonomyField.setFieldValueByValue by specifying SP.Taxonomy.TaxonomyFieldValue object multi-valued taxonomy field: SP.Taxonomy.TaxonomyField.setFieldValueByValueCollection Method by specifying ...


3

According to SharePoint 2013 Online App: 403 Response While Downloading Documents from a Document Library article this error occurs when using oAuth App authentication model since Microsoft.SharePoint.Client.File.OpenBinaryDirect method doesn't pass App token The solution is to use Microsoft.SharePoint.Client.File.OpenBinaryStream method instead as ...


3

It seems it occurs since sp.js library that contains SP.ClientContext class is not yet loaded when your code runs. Use SP.SOD.executeFunc to ensure that the specified sp.js library is loaded when the code runs. Try to change ApproveRejectRDA function to enclose it in SP.SOD.executeFunc like this: function ApproveRejectRDA(id, approved) { ...


3

As part of using AddFieldAsXml you need to provide the field's internal and staticname announcementy.Fields.AddFieldAsXml("<Field Type='User' DisplayName='Created By' StaticName='CreatedBy' Name='CreatedBy'/>", true, AddFieldOptions.AddToAllContentTypes); announcementy.Fields.AddFieldAsXml("<Field Type='DateTime' DisplayName='Date Created' ...


3

I'm assuming you're on a standard SharePoint page -- if so, you can use the _spPageContextInfo object's userId and userLoginName properties. They come along for the ride when the page is rendered. From my browser dev tools: >_spPageContextInfo.userId 1337 >_spPageContextInfo.userLoginName "somebody@somecompany.onmicrosoft.com" If you're dealing ...


3

Using SharePoint 2010 JSOM i would suggest the following approach to retrieve list item attachments: determine whether List Item contains attachments or not via ListItem.Attachments property in case if list List Item contains attachments, submit a second request to retrieve attachment files Example function ...


3

The following example demonstrates how to return web sites sorted by last modified date: function getWebs(success,error) { var ctx = SP.ClientContext.get_current(); var web = ctx.get_web(); var webs = web.getSubwebsForCurrentUser(null); ctx.load(webs); ctx.executeQueryAsync( function(){ var result = []; ...


3

One thing you can do is use SP.List.getItems(query) to query the 'Department' list for the item with the Title value you want. Once you get the list item, you can get its ID. (Keep in mind that the getItems(query) method will return a list item collection, even though that collection may only contain one item.) Your CAML query would look something like ...



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