Wednesday, 20 February 2013

CreateTaskWithContentType (02)

Create Custom Column(s)

Why would we make a custom site column? Why would you use the CreateTaskWithContentType activity if we didn't need custom columns. If you do not need a custom column, use the CreateTask activity.

1.) If you're still with me let's make a custom field/column whichever you prefer to call it. right click your project->Add->New Item->Empty Element

Make sure you have a SharePoint 2010 template selected in the left hand pane and pick the Empty Element Type in the centre pane, give it a name and click Add.

2.) Once you've added an empty element Item to your project define your column(s) as needed. I'm creating just one since this is not an exercise in defining site columns.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Field ID="{8F1F2378-C7F1-4D1B-BD4B-8F3951ECCB7D}"
         Name="spm_KiwiMango" 
         Group="Custom Workflow" 
         DisplayName="Kiwi Mango"
         Type="Text" 
         Sealed="FALSE" 
         ReadOnly="FALSE" 
         Hidden="FALSE"
         DisplaceOnUpgrade="TRUE"/>
</Elements>
that's mine make yours however you like.

Create Content Type for tasks

1.) Now you've probably made lots of content types, but for the love of god do not skip this part. To get started add a content type. Right click your project->Add->New Item
again make sure to have the SharePoint 2010 Template selected, pick the content type Object type give it a name  and click Add.

2.) When prompted which base type should this content type inherit from? select task

3.) This is what you get out of the box.
what you want it to look like is the following
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Task List (0x01080100) -->
  <ContentType ID="0x01080100d6b5580b746b4e68b032f3cdc88b6062"
               Name="spm_WorkFlow_CT"
               Group="Custom Content Types"
               Description="My Content Type"
               Inherits="TRUE"
               Version="0"
               Hidden="FALSE">
    <FieldRefs>
      <FieldRef ID="{8F1F2378-C7F1-4D1B-BD4B-8F3951ECCB7D}" Name="spm_KiwiMango" />
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <New>_layouts/WrkTaskIP.aspx‌​</New>
          <Display>_layouts/WrkTaskIP.aspx</Display>
          <Edit>_layouts/WrkTaskIP.aspx</Edit>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType
</Elements>
Not exactly your run of the mill content type. Things of note are
  • Inherit from the base type 0x01080100
  • Set the hidden attribute to false
  • Add your field ref
  • Specify a generic place holder for the forms, do this so that when we make the list definition the workflow doesn't use the OOTB (out of the box) forms. (FormUrls Schema Overview)
Wowzers looks like we're done with the content type. Next lets make us a list definition(again there's a trick to it, so don't stop paying attention.

It's List Definition Time

1.) Start like you would with any list definition from content type, right click your project->Add->New Item
Now as always make sure you have SP2010 template selected in the left hand pane, in the centre pane pick "List Definition From Content Type", give it a much more descriptive name then I did and hit Add.

2.) Next you'll be prompted to enter in a couple of details about your list definition a display name, which content type to use and whether to include a list instance.
So give your list definition a name, pick your content type, and well I never like to include my list instance with my list definition so I guess do what I'm doing or don't...

3.) Now open up your List Definitions elements file.
change the Type property to 107, this will define it as a task list

4.) Now with that complete you can open up the schema to inspect the difference you're content type made
It's not all that interesting but hey why not right?

5.) Declare a List Instance from the list Definition you just created. As always, right click your project-> Add Item->New
SP2010 template, List instance item, Descriptive name, Hit Add.

6.) Next you're going to have some list instance details to fill out.
Give it a name, make sure to select your List Definition, clean up the URL, if you want add it to the quick launch that's you're call or should be in your governance (whatever that is).

7.) Next deploy your solution, navigate to your root web and check on your list. if there's nothing there, then open up your feature and make sure that you include your columns, content type, list definition and list instance, the work flow is not necessary just yet.

http://[your site]:[your port number]/_layouts/viewlsts.aspx

now you should see something along the lines of

If you see a magical task list, having the clipboard icon with the check mark you where successful, if you have the list but the wrong icon go back to your list definition and change the type to 107, then go to your list instance and change the TemplateType attribute to 107, redeploy and check again. if you don't have the list start over I guess....

Continued