Friday, May 20, 2011

Introduction Word Automation Services in SharePoint 2010

Word Automation Services is a big part of that pillar, and represents our desire to ensure that the power and functionality of Word is available beyond the desktop; in this case, by enabling developers to harness the capabilities of Word on the server as part of SharePoint 2010.

What is Word Automation Services in SharePoint Server 2010?

Ever tried to transfer .docx files into PDF? Most of us try to perform server side conversions of Open XML files (.docx) into fixed formats (PDF and XPS) using the Word desktop application. Isn’t it? Now this conversion can be done hassle-free with Word Automation Services.

As an element of SharePoint 2010, Word Automation Services allows you to perform file operations on the server that previously required automating desktop Word:

* Converting between documents formats (e.g. DOC to DOCX)

* Converting to fixed formats (e.g. PDF or XPS)

* Updating fields

* Importing “alternate format chunks”

Features of Word Automation Services

Features of Word Automation Services include the following:

Reliability – Word Automation Service was built from the ground up to work in a server environment, which means that you no longer have to worry about issues like dialog boxes that bring the process to a halt, expecting a user to provide input; creating interactive user accounts under which to run the application to avoid running into permissions issues, etc.

Speed – The service is optimized to perform server-side file operations, and in doing so provides performance significantly better than existing solutions.

Scalability – The service can take advantage of the processing power available on typical server hardware (multiple processors, additional memory). For example, although a single instance of WINWORD.EXE can only utilize a single core of processing power, with Word Automation Services, you can specify the number of simultaneous conversions (and the # of processing cores) to use based on the available hardware.

What Word Automation Service doesn’t do?

One of the most important things to understand about Word Automation service is what it doesn’t do. Word Automation Service is not intended to be a 1:1 replacement for the existing desktop object model. Instead, the server is one half of a replacement for the existing object model – the other half being the Open XML SDK.

  • The SDK is designed to handle tasks that don’t require application logic, such as inserting or deleting content (paragraphs, tables, pictures), inserting data from other data sources, sanitizing content (removing content, accepting tracked changes), etc.
  • The service is designed to handle those few tasks that do need application logic: reading all of the document formats that Word supports, converting to all of the output format that Word supports, recalculating dynamic fields, etc.
In SharePoint 2010, you can add "Word Automation Services" from Central Admin as shown below

image

Once the service is in place, we can easily convert Word documents to PDF as shown in below snippet

private voidConvertDocFileToPDF(SPFile filex)
{
ConversionJobSettings settings = newConversionJobSettings();
settings.OutputFormat = SaveFormat.PDF;
ConversionJob job = newConversionJob(ConfigurationHelper.Instance.DocumentConversionService, settings);
job.UserToken = SPUserToken.SystemAccount;
stringpdfFile = filex.Url.Replace("docx", "pdf");
job.AddFile("http:///"+ filex.Url, "http:///"+ pdfFile);
job.Start();
}

Ensure to add reference to “Microsoft.Office.Word.Server” present under 14 hive “ISAPI” folder.

To test this, run “Word Automation Services Timer Job”

FAST Search for Sharepoint 2010 Query Logger

The FS4SP query logger will make it easier for developers and IT pro's to debug user queries.

This tool will monitor the internal query logs in FAST for SharePoint and re-execute the query and capture the result XML directly from the QR server. The xml will show what has been done to the query internally in FAST and is useful for debugging purposes.

As it uses the internal QR server in FAST it has to be run on a FAST query server.

Note
Using this tool in production might impose a security risk, as you will be able to execute and view results which you as a user/administrator might not have the rights to view.

File Download: Querylogger.exe

Fixing the SharePoint 2010 Breadcrumb

In SharePoint 2010 default masterpage (v4.master) has delivered Breadcrumbs in a new, and I think confusing, way.

SharePoint 2010 Breadcrumb

SharePoint 2010 Breadcrumb

From my perspective, this approach is difficult to use because it is hidden from the user. Once you know about it the breadcrumb is easier to find, but its nowhere near as usable as a traditional breadcrumb.

Smashing Magazine offers a range of alternatives you can consider in implementing your own breadcrumb which are worth considering if you want to create a fully-customised master page.

However, want if you want a breadcrumb of the same style as SP2007?

What if you want to revert the 2010 breadcrumb into the style of the 2007 breadcrumb? Well it turns out that the v3 masterpage(the 2007-style masterpage that runs on SharePoint 2010 to allow companies to avoid a visual upgrade) runs the old-school masterpage.

If you dive into the v3 masterpage (default.master) you can see the following snippet to in place of the breadcrumbs.

As it turns out, if you paste that snippet into the v4 masterpage it will work perfectly.

FAST Search for Sharepoint MOSS 2010 Query Tool

Tool to query FAST for SharePoint and SharePoint 2010 Enterprise Search. It utilizes the search web services to run your queries so you can test your queries remotely from your local machine. It shows your results, allows you to refine your query (FAST), and page your results.

The tool allows you to refine your query using the FAST search refiners and re-run your query to see the results. It has new added capability to use XRANK to alter the weighting of specific terms in your query.

File Download: Tool.exe

The tool was built in Visual Studio 2010 and .NET 4.0. The .NET 4.0 Client Profile is required to run the tool.

Create SharePoint 2010 workflow using SharePoint Designer

In this article, I'd be discussing about the creating SharePoint 2010 workflows using SharePoint Designer 2010. Rather than designing a workflow from scratch, I'd be re-using the workflow defined in Visio (Refer previous article).

Before getting into the workflow, I'm defining a content type by name ‘Invoice Report’ with three basic site-columns InvoiceAmount, Invoice Date and InvoiceDepartment to keep it simple.

site columns

content type

Create a new custom list by name ‘Invoice’ and attach the content type ‘InvoiceReport’ to it.

list

Navigate to Site Objects –> Workflow in SharePoint Designer

import from visio1[6]

Choose ‘invoice processing.wvi’ (workflow designed in the previous article) and click Next.

import from visio2

Choose ‘Reusable workflow’ as type of workflow (in this case i want this workflow to be re—used across lists that has associated invoice report content-type).

import from visio3

Click finish.

The workflow will look like the following in the designer.

workflow designer

Go to step ‘Log for starting’ and change the message to ‘workflow is starting’'.

Go to If statement under step ‘Invoice > 50K’ and define the expression like if Invoice Amount less than or equal to 50,000.

image

image

Set Workflow status to Approved under If loop.

image

Under log for Auto Approval, set the message ‘Workflow is Auto Approved’.

image

Go the Else part and configure the Task Approval process.

approval config

In this case, the Task Approval process will be executed if the invoice amount is greater than 50,000. The idea is to enforce a manual task approval process, approved by the manager.

The workflow design would look like the following:-

final workflow design

If you choose Custom Approval Process or Custom Task Process, you’ll get bunch of actions to customize the behavior of the single task or task process.

task behavior1

task behavior2

The Task Behavior Actions is one of the improved feature in SharePoint 2010 workflows. The Task behavior actions does not appear in Visio 2010, when you design workflows . It is available in SP Designer 2010 and VS 2010. The actions like Escalate Task may find a common usage. But in this case, I'm not customizing any task behavior, just sticking with the task behavior defined for the Approval Process in SP Designer 2010.

Check for errors and publish the workflow.

Go to the SharePoint site and associate the Invoice Processing workflow with the invoice list.

Under workflow settings –> Add a workflow

Set content type to ‘Invoice Report

Select ‘invoice processing’ under the workflow template

Set ‘Department Invoice workflow’ for the unique name of the workflow.

Set the workflow to be started manually

workflow setting

Create an invoice item in the list.

invoice new item

Start the workflow manually.

The invoice item would be approved, because the amount is less than 50K.

image

Let’s try with another invoice amount of 60, 000.

Start the workflow again.

Now the workflow is not auto-approved, task is assigned to the Manager and it is in progress state.

Log in as Manager to see the assigned Task.

task approval

Click ‘Approval’ button to approve the invoice.

We’ve created a very simple workflow in SharePoint Designer 2010.

Workflow: Reminder Before Due Date – MOSS vs. WSS

MOSS Reminder Workflow

  1. In the SharePoint task list, create a new column called Reminder Date, and set it as a Date field. Uncheck the “Add to default view” box, and click OK.
  2. We don’t want this field to be displayed to users when they are filling out the form, so we hide it.
    In the list’s settings, click Advanced Settings. Change Allow management of Content Types to Yes. Click OK.
  3. In the Content Types section of the list’s settings, click the name of the one content type in there. In this example, it’s “Task”. Then, in the List Content Type information screen, click the name of the Reminder Date field. Change it from Optional to Hidden, and click OK.
  4. Now it’s time to create a workflow that will set the Reminder Date. In SharePoint Designer, open the site, and click the File menu, and New… Workflow.
  5. Call it Task Reminder, and connect it to the Tasks list. Set it to run on create and on change.
  6. There need not be a condition, and the actions are the following:
    ”Add Time to Date”
    ”Set field in Current Item”

    (trick: to get that last underlined field to show a variable, choose workflow data as the source)
  7. Click Finish to save the workflow.

    Another important thing to note is that if your SharePoint Server has not been upgraded to service pack 2, this workflow could end up running in an infinite loop.
  8. Create a new item in the task list, and see this workflow in action. It fills in the Reminder Date field automatically. You can add this field to the default view, for testing purposes, so you’ll see the value get filled in.
  9. The next step is to create the workflow that actually sends the reminder email. Call it Task email, and uncheck all the boxes as so:
  10. Click Next.
  11. Create one action, to send an email to the person that the task is assigned to, and make the email say whatever you want. Then click Finish.
  12. Next, to set the policy… On the list settings screen, click Information Management Policy Settings. (This is only available in MOSS, not WSS)
  13. Click the name of the content type, in this case it is Task. Select Define a Policy, and click OK.
  14. Put a check box next to Enable Expiration. Fill in the section as follows. Remember, that when I created the Task Email workflow, I unchecked all the boxes that indicate when the workflow is supposed to run, but I can still kick it off using a policy!
  15. That’s it. Test it out. Make sure you fill in the Assigned To field on the tasks, so that the reminder email will go out.

Another note... It doesn’t let you put a ZERO here, for + 0 days. This is why I set my reminder date to calculate –8, since I know I’ll have to put a +1 here. Math. Negative 8 plus positive 1 equals negative 7, which equals a reminder 7 days ahead of the due date. Click OK.

About Information Management Policy settings and starting a workflow:
Each time after you edit the Task Email workflow in SharePoint Designer, you have to go back to the screen in the above screenshot, and RE-select the current workflow name, and click OK.

WSS Reminder Workflow

This section will show how different it is creating the same workflow in WSS. Since we don’t have the benefit of information management policy settings, we have to set a workflow to run, waiting for the reminder date to arrive.

  1. Create a new SharePoint Designer workflow, connect it to the tasks list, and set it to run each time a new item is created.
  2. The actions should be as follows:

    ”Add Time to Date”
    ”Log to History List”
    “Pause Until Date”
    ”Send an Email”

That’s all the WSS workflow entails, but there are a couple of drawbacks:

  • If the due date is more than about 2 or 3 months away, that paused workflow becomes more unreliable. There is an underlying “Workflow History” list on each site, and apparently it auto-purges records that are over 60 days old. I hear that this auto-purge can cause problems in long-running workflows.
  • Even if the workflow is set to run on create AND on item change, the reminder variable still doesn’t change when the task item’s due date is modified. There’s got to be a way around this, which would most likely entail a more complex workflow… but I’m sure it would have pausing involved.