You can build a batch string to delete all of the items from a SharePoint list like this:
1: //create new StringBuilder
2: StringBuilder batchString= new StringBuilder();
3:
4: //add the main text to the stringbuilder
5: batchString.Append("");
6:
7: //add each item to the batch string and give it a command Delete
8: foreach (SPListItem item in itemCollection)
9: {
10: //create a new method section
11: batchString.Append("");
12: //insert the listid to know where to delete from
13: batchString.Append("" + Convert.ToString(item.ParentList.ID) + "");
14: //the item to delete
15: batchString.Append("" + Convert.ToString(item.ID) + "");
16: //set the action you would like to preform
17: batchString.Append("Delete");
18: //close the method section
19: batchString.Append("");
20: }
21:
22: //close the batch section
23: batchString.Append("");
24:
25: //preform the batch
26: SPContext.Current.Web.ProcessBatchData(batchString.ToString());
The only disadvantage that I can think of right know is that all the items you delete will be put in the recycle bin. How can I prevent that?
I also found the solution like below:
// web is a the SPWeb object your lists belong to
// Before starting your deletion
web.Site.WebApplication.RecycleBinEnabled = false;
// When your are finished re-enable it
web.Site.WebApplication.RecycleBinEnabled = true;
Ref [Here](http://www.entwicklungsgedanken.de/2008/04/02/how-to-speed-up-the-deletion-of-large-amounts-of-list-items-within-sharepoint/)
But the disadvantage of that solution is that only future deletion will not be sent to the Recycle Bins but it will delete all existing items as well which user do not want. Any idea to prevent not to delete existing items?
Many thanks in advance,
TQT
I don't think is possible to bypass the recycle bin using batch update however you could modify you code to something like this
foreach (SPListItem item in itemCollection)
{
item.Delete(); //this wont go to the recycle bin
//or if you need to send it to the recycle bin then you can use
item.Recycle();
}
Related
I have a listview which has multiple rows and check boxes is enabled I tried to wrote a code that remove item when I unchecked the item checkbox as it is checked by default
In the itemcheck event
If(list.Focused == true)
{
If (e.newvalue == checkState.unchecked)
{
list.items.removeAt( e.index);
list.Refresh();
}
}
I got a outofrange exception and 1 is not a valid for index
'1' refer to the index of the item I removed
You have to test if index is in range (because the collection shrink). Add this test before removing elements :
if(list.items.count < e.index && e.index > 0)
Here is the solution in check event you have current value and new value the new value not be applied till the check event is complete if you delete the item the class throw outofrange as it is try to assign a property of deleted item
You can use a list to add the items in and in the event checked remove items and clear the list
1)Want to disable line item fields on Custom Transaction form.
Below is the snippet I tried & applied to the form's custom code on LINE INIT FUNCTION function but it doesn't work. Does it work or is it a bug or something I am missing here.Please suggest
function lineInit(){
if(type == 'item'){
var itemDisFields = ['description','location'];
for(var i = 0; i < itemDisFields.length; i++){
nlapiDisableLineItemField('item',itemDisFields[i] , true);
}
}
}
2)How to freeze Add button in the line level.
Sublist indices in SuiteScript 1.0 start at 1, not 0, so you'll need to start i at 1.
I am not exactly sure what you mean by "freeze" the Add button, but there is no supported way to do this. You could of course hack it with jQuery. The best supported way to prevent a line from being added is to use a validateLine handler and return false from it when the line should not be added.
I'm triing to update customer subscriptions list in netsuite.
var itemCount = recLead.getLineItemCount('subscriptions');
for (var i = 1; i < itemCount; i++ ) { recLead.setCurrentLineItemValue('subscriptions', 'subscribed', 'T');}
But error throws:
Notice (SuiteScript)
You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.
If you are planning on using the "current" line item function, then you do need to select the line to use. As below:
var itemCount=recLead.getLineItemCount('subscriptions');
for(var i=1;i<=itemCount;i++){
recLead.selectLineItem('item',i);
recLead.setCurrentLineItemValue('subscriptions','subscribed','T');
recLead.commitLineItem('item');
}
Alternatively, if you do not want to do it that way, you can use setLineItemValue, instead.
var itemCount=recLead.getLineItemCount('subscriptions');
for(var i=1;i<=itemCount;i++){
recLead.setLineItemValue('subscriptions','subscribed',i,'T');
}
Both, effectively, work the same.
BTW, since you have to start at row 1, you need to make sure you use i<=itemCount. Otherwise, if there are 10 rows, you will miss the last row. When you move to 2.0, and start your count at 0, you can use i< itemCount.
Before using setCurrentLineItemValue, you need to select the line using selectLineItem then commitLineItem to save the changes.
Not sure what I'm doing wrong, but here is the code
1: var currDoc:NotesDocument = currentDocument;
2: var doc:NotesDocument = database.createDocument();
3: doc.replaceItemValue("form", "Memo");
4: doc.replaceItemValue("sendTo", currDoc.getItemValueString("responsible"));
5: doc.replaceItemValue("subject", currDoc.getItemValueString("replySubject"));
6: var rtitem:NotesRichTextItem = doc.createRichTextItem("Body");
7: rtitem.appendText("The following more information request has been answered:");
8: rtitem.addNewLine(2);
9: rtitem.appendText("Subject: " + currDoc.getItemValueString("replySubject"));
10: rtitem.addNewLine(2);
11: rtitem.appendText("Reply Text: " + currDoc.getItemValueString("replyText"));
12: rtitem.addNewLine(2);
13: rtitem.appendDocLink(currDoc);
14: doc.send();
Problem on line 13 (what are the chances of that)
Error while executing JavaScript action expression
Script interpreter error, line=13, col=8: [TypeError] Method NotesRichTextItem.appendDocLink(NotesXspDocument) not found, or illegal parameters, when I comment out line 13 the rest of the code works fine, sends the email with the content from the document I am trying to pass to the email.
Couple of things...
First of all make sure that your NSF has a default view setup. Doclinks won't work if there is no default view. You can tell if there is a default view by the presence of a gold star beside one of the views in designer.
From the error message it looks like your passing a NotesXspDocument into the appendDocLink method while it is expecting a NotesDocument. the first line of code should really be
var currDoc:NotesDocument = currentDocument.getDocument(true)
Also, has the document been saved at this point, if not then you should add a line
currDoc.save(true,true)
and this will make sure that the document is saved, You can't send a DocLink without the document UNID and an unsaved document will not have a valid UNID.
I am working on the project where i had used choice group in form. Now I want to get the selected item or index number of the choice group and want to perform some action.
I had tried through this:-
System.out.println(cgPrefs.getString(i) + (selected[i] ? ": selected" : ": not selected"));
But I am not getting the exact index number of the selected item in choice group.
You will get flags according to selection
boolean[] selectedFlag = new boolean[getChoiceGroup().size()];
using getSelectedFlags() method
getChoiceGroup().getSelectedFlags(selectedFlag);//getChoiceGroup() returns object of choicegroup
Now iterate and print
for(int i = 0 ; i < selectedFlag.length; i ++){
if(selectedFlag[i]){
System.out.println("Selected : "+getChoiceGroup().getString(i));
}else{
System.out.println("Not Selected : "+getChoiceGroup().getString(i));
}
}