Hot answers tagged

12

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


8

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


8

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


8

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


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

Here is a basic example of how to get the selected items with javascript: var ctx = SP.ClientContext.get_current(); var items = SP.ListOperation.Selection.getSelectedItems(ctx); var myItems = ''; var i; for (i in items) { myItems += '|' + items[i].id; } Complete code for opening a modal page passing in list id and selected items: function ...


7

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


6

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


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


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

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


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


4

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


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

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


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


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


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

According to your question description, It seems 1 Related Item is a lookup column value. Showing Link In this value, you have lookup item's Id. If we know list name and item's Id, then we can construct the item's display link manually. var listName = "Your List Name"; var itemId = ctx.currentItem.RelatedItem[0].lookupId; var displayUrl = ...


3

I found a way. There is a class FieldUrlValue in the Client Ojbect Model for this type of situations. Here's how I implemented it: ListItemCreationInformation lici = new ListItemCreationInformation(); ListItem item = list.AddItem(lici); FieldUrlValue link = new FieldUrlValue(); link.Url = "http://some-address"; link.Description = "Some Address Title"; ...


3

This is why you shouldn't use Folders in SharePoint, change your folder structure to a MetaData tree and you won't have this issue.


3

I found solution which runs perfectly in my case: Use LockedByUser property of SPUser class. The code item.File.LockedByUser.LoginName returns the user's log-in name who has locked the file. If it is not locked by anyone then it returns null. The code is as below: static void Main(string[] args) { using (SPSite siteCollection = new SPSite(@"")) ...


3

No, no OOB settings can prevent a user from overwriting an existing document, unless you do one of the things suggested in the other answers OR you create an event receiver and attach it to your library. In this event receiver, for the itemAdding event handler, you then check if there's another document with the same name and in this case, you cancel the ...


3

Did you even try to google? http://mysharepointlearnings.wordpress.com/2013/11/20/knockout-js-with-sharepoint-2013-app-ii/ There are plenty of results regarding your problem.


3

You are looking for Auditing. But be careful, it can pretty fast get out of control and fill the servers hard drive and affect the performance. Make sure to trim the Audit logs to fit your requirements. Another god idea is to have SharePoint writing the log files to a separate drive. You can use the audit feature of Microsoft SharePoint Server 2013 to ...


3

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


3

You can add a column render callback when you specify columns definition. "aoColumns": [ { "sTitle": "Shootout By", "mData": "Employee", "sWidth": "10%" }, { "sTitle": "Shoutout Date", "mData": "CreatedOn", "sWidth": "8%" }, { "sTitle": "Title", "mData": "Title", "sWidth": "10%", "render":function (data, type, row, meta) { return ...


3

You can use Event Receiver for this feature. So in item adding event you have to check whether the user who is adding item has already added any item for today.If yes then stop him for adding more item.


3

Create a calculated column and concat "https://link/sites/sitename/Lists/listname/DispForm.aspx?ID=" and item id. This will suffice your requirement. Also if you want to display column value as a link, check out this link. If workflow is an option, you can start a workflow on item created and set a hyperlink column with item's display form URL. Check the ...



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