January 14, 2013

Integrating Nintex Workflow with Twitter Pt. 1


One common scenario for corporate Internet sites is to sent notifications when a new article is published via social networks to their followers. With the availability of Nintex Live it became possible to twitter a tweet. In one of the later versions a similar activity for Yammer became available. In this post I will show how you can use the "Twitter a Tweet" activity to notify your Twitter followers about new articles.

This is going to be a two part series. In the first part I will create a News Page content type and page layout. In the second part I will show you the workflow which ensures that every time a News Page was approved the notification is sent to Twitter.

Step 1: Content Type News Page

In order to get started open Visual Studio 2010 and create an empty SharePoint project. Then add a new content type to this project based on Page.

Modify the added content type to look like the this:

   1:  <!-- Parent ContentType: Page (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39) -->
   2:    <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900d765018dfe204899adbdfeca8fd70d8f"
   3:                 Name="News Page"
   4:                 Group="Social Media"
   5:                 Description="News Page with Twitter Message"
   6:                 Inherits="TRUE"
   7:                 Version="0">

Step 2: Field Twitter Message

The field is used by editors to define the message which is sent to Twitter.  Just add before the content type declaration from step 1 following field:

   1:  <Field ID="{D46E8C75-4C20-4118-A367-A553429602F0}"
   2:         StaticName="TWITTERMESSAGE"
   3:         Name="TWITTERMESSAGE"
   4:         Title="Twitter Message"
   5:         DisplayName="Twitter Message"
   6:         Type="Text"
   7:         Group="Social Media"
   8:         TextOnly="TRUE"
   9:         ShowAlways="TRUE"
  10:         Hidden="FALSE"
  11:         MaxLength="119"
  12:           />

Please note: MaxLength (line 11) is set to 119. This allows us to append URL to the article during the workflow.

Then add the field to the News Page content type declaration:

   1:  <!-- Parent ContentType: Page (0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39) -->
   2:    <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900d765018dfe204899adbdfeca8fd70d8f"
   3:                 Name="News Page"
   4:                 Group="Social Media"
   5:                 Description="News Page with Twitter Message"
   6:                 Inherits="TRUE"
   7:                 Version="0">
   8:      <FieldRefs>
   9:          <FieldRef ID="{D46E8C75-4C20-4118-A367-A553429602F0}" Name="TWITTERMESSAGE" Required="TRUE"/>
  10:      </FieldRefs>
  11:    </ContentType>

Step 3: Binding the News Page to the library Pages

And finally before the closing Elements tag insert the content type binding. This ensures that the content type is available in the library Pages.

   1:  <!-- Bind Content Type to Pages library-->
   2:      <ContentTypeBinding
   3:          ContentTypeId="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900d765018dfe204899adbdfeca8fd70d8f"
   4:          ListUrl="$Resources:cmscore,List_Pages_UrlName;"
   5:          />

Step 4: Adding the Page Layout

As of now we have defined the content type News Page and have added a field to hold the message sent to Twitter. What is still missing is a page layout which allow editors to create a news page and define the message content. Add a new module named PageLayouts to the project. Then rename the file Sample.txt to NewsPage.aspx.

Open NewsPage.aspx and paste the following code into the file:

   1:  <%@ Page language="C#"   Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
   2:  <%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
   3:  <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
   4:  <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
   5:  <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
   7:  <asp:Content ContentPlaceholderID="PlaceHolderAdditionalPageHead" runat="server">
   8:      <SharePointWebControls:UIVersionedContent ID="UIVersionedContent1" UIVersion="4" runat="server">
   9:          <ContentTemplate>
  10:              <SharePointWebControls:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/pageLayouts.css %>" runat="server"/>
  11:              <PublishingWebControls:editmodepanel runat="server" id="editmodestyles">
  12:                  <!-- Styles for edit mode only-->
  13:                  <SharePointWebControls:CssRegistration ID="CssRegistration1" name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/zz2_editMode.css %>" runat="server"/>
  14:                  <style>
  15:                      .ms-long{width:900px !important;}
  16:                  </style>
  17:              </PublishingWebControls:editmodepanel>
  18:          </ContentTemplate>
  19:      </SharePointWebControls:UIVersionedContent>
  20:      <SharePointWebControls:UIVersionedContent ID="UIVersionedContent2" UIVersion="4" runat="server">
  21:          <ContentTemplate>
  22:              <SharePointWebControls:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/page-layouts-21.css %>" runat="server"/>
  23:              <PublishingWebControls:EditModePanel ID="EditModePanel1" runat="server">
  24:                  <!-- Styles for edit mode only-->
  25:                  <SharePointWebControls:CssRegistration ID="CssRegistration2" name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/edit-mode-21.css %>"
  26:                      After="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/page-layouts-21.css %>" runat="server"/>
  27:              </PublishingWebControls:EditModePanel>
  28:          </ContentTemplate>
  29:      </SharePointWebControls:UIVersionedContent>
  30:      <SharePointWebControls:CssRegistration ID="CssRegistration3" name="<% $SPUrl:~sitecollection/Style Library/~language/Core Styles/rca.css %>" runat="server"/>
  31:      <SharePointWebControls:FieldValue id="PageStylesField" FieldName="HeaderStyleDefinitions" runat="server"/>
  32:  </asp:Content>
  35:  <asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
  36:      <SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
  37:  </asp:Content>
  40:  <asp:Content ContentPlaceholderID="PlaceHolderPageTitleInTitleArea" runat="server">
  41:      <SharePointWebControls:UIVersionedContent ID="UIVersionedContent3" UIVersion="4" runat="server">
  42:          <ContentTemplate>
  43:              <SharePointWebControls:TextField runat="server" id="TitleField" FieldName="Title"/>
  44:          </ContentTemplate>
  45:      </SharePointWebControls:UIVersionedContent>
  46:      <SharePointWebControls:UIVersionedContent ID="UIVersionedContent4" UIVersion="4" runat="server">
  47:          <ContentTemplate>
  48:              <SharePointWebControls:FieldValue FieldName="Title" runat="server"/>
  49:          </ContentTemplate>
  50:      </SharePointWebControls:UIVersionedContent>
  51:  </asp:Content>
  54:  <asp:Content ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server">
  55:      <SharePointWebControls:VersionedPlaceHolder ID="VersionedPlaceHolder1" UIVersion="4" runat="server">
  56:          <ContentTemplate>
  57:              <asp:SiteMapPath ID="siteMapPath" runat="server" SiteMapProvider="CurrentNavigation" RenderCurrentNodeAsLink="false" SkipLinkText="" CurrentNodeStyle-CssClass="current" NodeStyle-CssClass="ms-sitemapdirectional"/>
  58:          </ContentTemplate>
  59:      </SharePointWebControls:VersionedPlaceHolder>
  60:      <SharePointWebControls:UIVersionedContent ID="UIVersionedContent5" UIVersion="4" runat="server">
  61:          <ContentTemplate>
  62:              <SharePointWebControls:ListSiteMapPath runat="server" SiteMapProviders="CurrentNavigation" RenderCurrentNodeAsLink="false" PathSeparator="" CssClass="s4-breadcrumb" NodeStyle-CssClass="s4-breadcrumbNode" CurrentNodeStyle-CssClass="s4-breadcrumbCurrentNode" RootNodeStyle-CssClass="s4-breadcrumbRootNode" NodeImageOffsetX=0 NodeImageOffsetY=353 NodeImageWidth=16 NodeImageHeight=16 NodeImageUrl="/_layouts/images/fgimg.png" HideInteriorRootNodes="true" SkipLinkText="" />
  63:          </ContentTemplate>
  64:      </SharePointWebControls:UIVersionedContent>
  65:  </asp:Content>
  68:  <asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
  69:      <SharePointWebControls:UIVersionedContent ID="UIVersionedContent6" UIVersion="4" runat="server">
  70:          <ContentTemplate>
  71:              <table id="MSO_ContentTable" cellpadding="0" cellspacing="0" border="0" width="100%">
  72:                  <tr>
  73:                      <td>
  74:                          <div class="pageContent">
  75:                              <PublishingWebControls:RichHtmlField id="content" FieldName="PublishingPageContent" runat="server" />
  76:                          </div>
  77:                      </td>
  78:                  </tr>
  79:              </table>
  80:              <PublishingWebControls:editmodepanel runat="server" id="editmodepanel2">
  81:                  <!-- Add field controls here to bind custom metadata viewable and editable in edit mode only.-->                
  82:                  <table cellpadding="10" cellspacing="0" align="left" class="editModePanel" width="100%">
  83:                      <tr valign="top">
  84:                          <td>
  85:                              <asp:label text="Please enter your twitter message." runat="server" />
  86:                          </td>
  87:                          <td width="950">
  88:                              <SharePointWebControls:TextField FieldName="TWITTERMESSAGE" runat="server" />
  89:                          </td>
  90:                      </tr>
  91:                  </table>            
  92:              </PublishingWebControls:editmodepanel>
  93:          </ContentTemplate>
  94:      </SharePointWebControls:UIVersionedContent>
  95:  </asp:Content>

In line 80 the edit mode panel begins. This section is only displayed when a user edits the page. This is where we allow the editor to enter the Twitter message. In line 88 we bind a TextField control to the field TWITTERMESSAGE of the content type.

Step 5: Binding the Page Layout to the Content Type

Although we have just defined the page layout. there is currently no binding between the page layout and the content type. In order to create this binding, update the elements.xml of the module with these lines:

   1:  <Module Name="PageLayouts" Url="_catalogs/masterpage" Path="PageLayouts" >
   2:        <File Path="NewsPage.aspx" Url="PageLayouts/NewsPage.aspx" Type="GhostableInLibrary">
   3:            <Property
   4:                  Name="PublishingAssociatedContentType"
   5:                  Value=";#News Page;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900d765018dfe204899adbdfeca8fd70d8f"/>
   6:            <Property
   7:                Name="Title"
   8:                Value="News Page (Twitter)"/>
   9:        </File>
  10:  </Module>

The first Property element binds the page layout to the content type.


During this post we have create a content type which has a page layout and stores a twitter message. The next post will be covering the workflow will be available by next week.

Complete code from this week is available on codeplex: http://vsanner.codeplex.com, Project: 2013-01 SocialMedia-1