How to create a OOTB Workflow Tasks List - sharepoint

I am hearing about OOTB Workflow Tasks List, but I'm not being able to find any direct way to create a Workflow Tasks List (like a Tasks or a Project Tasks List). Is there any list definition for a Workflow Tasks list really?

The Workflow Tasks list created in a Publishing site, is an OOTB Tasks list.
http://mysharepoint.com/_layouts/new.aspx?FeatureId={00bfea71-a83e-497e-9ba0-7a5c597d0107}&ListTemplate=107
Here is the code from Microsoft.SharePoint.Publishing.Internal.ProvisioningHelper.CreateApprovalTaskList:
bool newListCreated = false;
list = ProvisioningHelper.AddList(
lists,
"WorkflowTasks",
"$Resources:cmscore,ListNameWorkflowTasks;",
"$Resources:cmscore,ListDescriptionWorkflowTasks;",
WssFeatureIds.TasksList,
(Guid[]) null,
SPListTemplateType.Tasks,
out newListCreated);
if (newListCreated)
{
list.EnableDeployWithDependentList = false;
list.AllowDeletion = false;
list.Update();
ProvisioningHelper.DisableCrawlOnList(list);
}

Related

Why does DocumentHelper.CopyDocument place the new document in "Published" workflow step?

I'm trying to copy a document using the Kentico 11 API and when using Document.CopyDocument the resulting TreeNode is automatically placed into the "Published" workflow step instead of "Edit" as one would expect. Is there any way to prevent this from happening?
I've tried both methods for DocumentHelper.CopyDocument including the method using CopyDocumentSettings, neither give the option to specify the initial workflow step.
TreeNode newDoc = DocumentHelper.CopyDocument(document, parentDoc, true, _treeProvider);
// also tried this
TreeNode newDoc = DocumentHelper.CopyDocument(new CopyDocumentSettings(document, parentDoc, _treeProvider));
Neither give me the option to specify workflow step, they only push it into "published". I can create a new version of the document, but that doesn't prevent the copy from being published initially.
I believe it copies the workflow status of the current page but I could be wrong. What I'd suggest is below. This code checks to see if the page is using check in/out and then uses workflow to set the newly created page to the first step in the workflow (which should be "edit").
TreeProvider tree = new TreeProvider();
var treeNode = DocumentHelper.GetDocument(4, tree);
var targetNode = DocumentHelper.GetDocument(5, tree);
CMS.DocumentEngine.TreeNode newPage = DocumentHelper.CopyDocument(treeNode, targetNode, false);
WorkflowManager workflowManager = WorkflowManager.GetInstance(tree);
WorkflowInfo workflow = workflowManager.GetNodeWorkflow(page);
if (!newPage.IsCheckedOut)
{
newPage.CheckOut();
}
if (workflow != null)
{
if (!workflow.WorkflowAutoPublishChanges)
{
newPage.MoveToFirstStep("Copying the page from another page.");
}
}
if (newPage.IsCheckedOut)
{
newPage.CheckIn();
}
I should have waited longer to post this question, turns out you can use the WorkflowManager in the API to push the document to the first step in the workflow:
newDoc.WorkflowManager.MoveToFirstStep(newDoc);
That pushes the document to the "Edit" step without affecting the workflow history, its as if the document was never published.

SPQuery and RowLimit

I have around 10000+ rows(Listitems) in a list I want to query.
I want to iterate each of the item in a timerJob - but I cant take all of them at a time
since : Object Model Override - NO, ListView threshold - 1000 - in the FARM level and i we cant change this.
What is the way for me to iterate all the 10000+ (like a batch) ??
You should use a ContentIterator. This will allow you to iterate over the contents of very large lists without triggering an SPQueryThrottledException.
For example:
SPList list = SPContext.Current.Web.Lists["MyList"];
// Build query using an iterator-defined WHERE clause
string query = string.Format("<Where><Eq><FieldRef Name='MyFieldName'/><Value Type='Text'>MyFieldValue</Value></Eq></Where>{0}", ContentIterator.ItemEnumerationOrderByNVPField);
// Instantiate iterator and use it to process the list
ContentIterator iterator = new ContentIterator();
iterator.ProcessListItems(list, query, ProcessListItem, ProcessListItemError);
Then you'd define your ProcessListItem and ProcessListItemError thusly:
static void ProcessListItem(SPListItem item) {
Console.WriteLine("ProcessListItem: Name {0}", item.Title);
}
static bool ProcessListItemError(SPListItem item, Exception e) {
Console.WriteLine("ERROR: message {0}", e.Message);
return true;
}
I'd also recommend you review Microsoft's Best Practices with SharePoint Server articles, in particular "Writing Efficient Code In SharePoint Server", which further discusses properly writing queries.

Add SharePoint workflow to a list programmatically

We are using SharePoint Foundation 2010.
We have created a workflow that checks the status of a task list.
If we associate the workflow with the list in the SharePoint UI it works fine.
We were wondering how we could automatically associate it, maybe in the feature receiver code that sets ut the site?
// 1. create an instance of the SPWorkflowAssociation class
SPWorkflowAssociation workflowAssociation =
SPWorkflowAssociation.CreateListAssociation(workflowTemplate, associationName, taskList, historyList);
// 2. set start options
workflowAssociation.AllowManual = true;
workflowAssociation.AutoStartChange = false;
workflowAssociation.AutoStartCreate = false;
// 3. set additional association options (if any)
workflowAssociation.AssociationData = associationData;
// 4. add workflow association to the list
list.WorkflowAssociations.Add(workflowAssociation);
// 5. enable workflow association, so it is displayed in the user interface
workflowAssociation.Enabled = true;

SharePoint 2007 : Get all list items in a list regardless of view from web service?

I need to check for duplicates. Currently I have items stored in sub folders in a list.
How can I retrieve all items in the list from a web service, so I can check for duplicates?
Here is code from object model: I want to do exactly this, but from a web service
private static void PrintItemTitles()
{
string strUrl = "http://localhost:8099/";
using (SPSite site = new SPSite(strUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["MyList"];
SPListItemCollection items = list.Items;
foreach (SPListItem item in items)
if (item != null)
Console.WriteLine(item.Title);
}
}
}
Use SPList.Items doesn't return all items? Well, then try SPList.GetItems(SPQuery).
Have a following SPQuery:
SPQuery query = new SPQuery();
query.ViewFields = "<FieldRef Name='ID'/><FieldRef Name='Title'/>";
query.Query = String.Format("<Where><Eq><FieldRef Name='Title'/><Value Type='Text'>{0}</Value></Eq></Where>", someItemTitle)
query.MeetingInstanceId = -1; //In case if you query recurring meeting workspace - get items from all meetings
query.RowLimit = 10; //Will you have more than 10 duplicates? Increase this value
query.ViewAttributes = "Scope='RecursiveAll'"; //Also return items from folders subfolders
Note: There could be some mistakes in code, because i`m writing from top of my head
By executing this query and if it returns more than one item, then you have a duplicate!
Edit: Ahh, sorry, you are talking about Web Services.
Then this code won't help. There are 2 options then:
Option 1: You CAN create a view that
does include items even from folders
(flat view). See here for
instructions.
Option 2: According to Lists Web Service's GetListItems method, you can pass QueryOptions parameter. Pass in
<QueryOptions>
<MeetingInstanceID>-1</MeetingInstanceID> <!-- Again, if you query recurring meeting, you want ALL items -->
<ViewAttributes Scope='RecursiveAll' /> <!-- or Recursive if that does not work -->
</QueryOptions>
Good luck!
You can use the Lists.asmx web service, but that is quite hard to do as it returns quite a lot of information. I would deploy a custom web service on my SharePoint environment that contains that code and returns the list items.

SharePoint: How do I create a new list from a list template?

I've created a list template based on an Issue list and it is saved in the List Template Gallery. Now how do I create a new list based on this template?
string internalName = "MyListTemplateName";
SPListTemplate t = null;
foreach (SPListTemplate template in web.ListTemplates)
{
if (template.InternalName.Equals(internalName)
{
t = template;
break;
}
}
web.Lists.Add("nameoflist", "description", t);
I just encountered the same situation today.
I saved a list as a template and i wanted to use that template in a new list.
On Sharepoint 2013, go to Site Contents > Add an App >
Scroll down and you will see a page numbering saying that you are on page 1
Click on the second page and all your saved templates will be there
It probably just took a while for the timer job to fire.
The template eventually showed up as an option under Lists > Create > Tracking section after a few minutes.
I'm surprised that Johan Leino's answer is marked as useful multiple times as it doesn't work in this particular case. If you create a template yourself, web.ListTemplates does not store it and you won't be able to create the list. It's only working for out-of-the-box templates.If you want to create a list based on your custom template you need to do it this way:
SPListTemplateCollection listTemplates = web.Site.GetCustomListTemplates(web);
SPListTemplate listTemplate = listTemplates["MyCustomTemplate"];
Guid listId = web.Lists.Add("My New List Name", "My Description", listTemplate);
if (listId != null) { //all good }

Resources