Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
13

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


13

Here is a basic example of how to get the selected items with javascript: var items = SP.ListOperation.Selection.getSelectedItems(); var myItems = ''; var i; myItems = items.map(function (v) { return '|' + v.id; }).join(''); Complete code for opening a modal page passing in list id and selected items: function resultCallback(result, value) { SP....


12

How about a simple query: /_api/web/lists/getbytitle('<list title>')/items(<item id>) which will return all the field values for a list item with some limitation for User/Lookup fields: only lookup id values will be retrieved. In order to request all the field values including User/Lookup field values, you could specify * to select all the ...


10

@Ashish Patel answer does not actually work when i tried but i was able to figure it out a bit differently. Here is my version of the helper method based on example provided by code ninja blog, here: private List<Guid> GetTermsIds(SPListItem listItem, string fieldName) { var taxonomyField = listItem.Fields.GetFieldByInternalName(fieldName) as ...


10

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>" + "<Eq&...


9

AllowUnsafeUpdates=true; is not required to add/delete/update list items unless you are doing these operations in Page_Load or other Get methods. Both CASE 1 and CASE 2 does not look good in terms of best practice. Problems with both case code: Do not use oSPWeb.Lists["MyList"]; instead use oSPWeb.Lists.TryGetList("MyList1"); Do not use list.Items.Add(); ...


8

Save the list as a template and recreate the list. ID columns will always keep incrementing and will never be reused.


7

This is how you do it TaxonomyFieldValueCollection tfvc = (list.Items[0]["Field Name"] as TaxonomyFieldValueCollection); var valuesList = (from v in tfvc select v.Label).ToList();


7

_spPageContextInfo Object could be used for retrieving information about current page on the client side, specifically pageListId property returns the current List Id. List Item Id could be extracted from a query string in Display/Edit pages, SharePoint client API GetUrlKeyValue function is used that purpose in the below example. The example demonstrates ...


7

Refer following steps to set Retention / Information management policy : Goto list settings click on Information management policy settings click on Item content type tick on Enable retention check box click on Add retention stage fill out the Action and the Event Click OK Done Remember this retention policy will not run immediately after you are done with ...


6

Here is a script that gets the UniqueId of a list item: <script type="text/javascript"> $(document).ready(function() { ExecuteOrDelayUntilScriptLoaded( function() { var itemId = ....; // change to the real id var listTitle = .... // the list title var ctx = SP.ClientContext....


6

Try to use this endpoint GetFolderByServerRelativeUrl to return all files and folder at a specific folder URL https://server/_api/Web/GetFolderByServerRelativeUrl(<folder url>)?$expand=Folders,Files To return only all files at a specific folder URL https://server/_api/Web/GetFolderByServerRelativeUrl(<folder url>)?$expand=Files For more ...


5

If you are calling the ItemAdding event, the ListItemId is not going to exist yet. Try using the ItemAdded event instead.


5

Navigate to corresponding Elements.xml, and you will notice Receivers element with ListTemplateId attribute, like this: <Receivers ListTemplateId="100"> ... </Receivers> What you need is to use ListUrl attribute instead, and point it to the specific list using provided url. There is a how-to on this on MSDN: http://msdn.microsoft.com/en-us/...


5

So let's go with your first request. You want a piece of code to run when a list item is deleted from a list but it has to be 100% javascript and there can't be any page postbacks. Obviously we must assume the page is going to stay open the entire time. You are left with using web services or CSOM to achieve this. My recommendation would be to use ...


5

You could perform this via CSOM/REST API. Use SP.Web.getFileByServerRelativeUrl Method to request File object and specify SP.File.listItemAllFields property to load list item field values for the list item corresponding to the file: var ctx = SP.ClientContext.get_current(); var file = ctx.get_web().getFileByServerRelativeUrl(url); //get file ...


5

You can add OOTB SharePoint rating to a list. Go to the list > list settings > rating settings. Set "Allow items in this list to be rated?" to Yes and choose between having "Likes" or "Star ratings". Enable users to rate content


5

Most probably the error File not found occurs since you are trying to retrieve attachments folder that not yet exist in method HasListItemAttachment The following example demonstrates how to upload attachment file via SharePoint JSOM: function processUpload(fileInput, listTitle, itemId,success,error) { var reader = new FileReader(); reader.onload = ...


5

Note: Since june 2017 this answer no longer applies for SharePoint versions; Microsoft disabled the use of JavaScript in a Calculated Columns For long explanation and work arounds see: June 13th 2017 Microsoft blocked handling HTML markup in SharePoint calculated fields - how to get the same functionality back Original answer: Disclaimer: The best ...


5

The REST API does not have complete support for folders - particularly when it comes to working with list items. While it's quite possible that there is a way to get this to work using the REST API, you're much better off using the Client Object Model in this case. See: SP2013 : Create a list item inside a folder


5

As per the documentation by Microsoft, you cannot select more than 100 items for bulk operations. The documentation says that: Where Boundary means you cannot configure the value. Its hard coded.


4

As long as the source and target lists are in the same site collection, you can move them with Manage Content and Structure (_layouts/sitemanager.aspx.


4

Try something like: string siteUrl = "http://MyServer/sites/MySiteCollection"; ClientContext clientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements"); clientContext.Load(oList); clientContext.ExecuteQuery() ListItem oListItem = oList.GetItemById(2); clientContext.Load(oListItem); clientContext....


4

Well, SPSecurity.RunWithElevatedPrivileges should do the trick. Make sure, you create a new SPSite/SPWeb within the elevated code block: var siteId = SPContext.Current.Site.ID; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(siteId)) { //do things on the new site object } });


4

SPExportObject/SPImportObject can be used to migrate the list item, but only issue that you need to take care is if you export an item from a database (e.g. a list) without exporting it's parent, then the exported item will become orphaned in the package. A package can contain multiple different orphaned objects (e.g. if you export multiple different lists ...


4

You should check more carefully what you are doing in the code. For example in the line TaxonomyField taxField = (TaxonomyField)item["Dept"]; you are trying to cast TaxonomyFieldValue object to TaxonomyField, which is incorrect, so you get ArgumentNullException on the next line because taxField becomes null. And you are resetting item field value for each ...


4

Check out this MSDN article which might help you out. Here's Microsoft's example code for adding a single item to a list (title field only): //Execute a REST request to get the form digest. All POST requests that change the state of resources on the host //Web require the form digest in the request header. HttpWebRequest contextinfoRequest = (...


4

Change NULL to null. I tried the following - first test resulted in a 400 Bad Request error, the second one worked fine. {'__metadata': { 'type': 'SP.Data.TasksListItem' },'StartDate': NULL} {'__metadata': { 'type': 'SP.Data.TasksListItem' },'StartDate': null}


4

You can make use of JavaScript Date Object for that. For example, while reading the data var scheduledTime = new Date(oListItem["ScheduledTime"]); Now you can calculate the new Time as follows var today = new Date(); var newScheduledTime = new Date(today.getYear(), today.getMonth(), today.getDate(), scheduledTime.getHours(), scheduledTime.getMinutes(), ...


4

Example: how to move list item into a folder via SharePoint JSOM API /** * Move ListItem * @param {SP.ListItem} list item * @param {string} targetFolderUrl - server relative url of folder where listitem needs to be moved */ function moveListItem(listItem,targetFolderUrl,success,error){ var ctx = listItem.get_context(); ctx.load(listItem,['...


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