Archive for May, 2008

Logging Workflows for Troubleshooting

SharePoint workflows are very powerful tools. SharePoint workflows allow you to automate tasks and workflow processes. If you haven’t used workflows before, I recommend reading the SharePoint online help for workflows:

http://office.microsoft.com/en-us/sharepointdesigner/CH100667661033.aspx

Once you start to use workflows in your SharePoint applications, you realise a very important and fundamental truth; what happens when a workflow fails? By default, you can click on an item in a list and see the workflow history. Unfortunately, the error messages in the workflow can be cryptic to say the least. For example, if I have a workflow that creates new items in 5 different lists and the workflow fails, I get a message saying “Unable to update list item”. The message doesn’t tell me which specific action or step failed or which list it was unable to write to.

To get around this issue, and to provide an even finer level of control over my workflows, I created a custom list and used that list to log my workflow actions. The custom list, called WorkflowLog, contains the following fields:

  • Workflow Name (text field) – stores the name of the workflow that is logging the event.
  • EventOccurred (date & time field) – stores the date and time that the event was completed.
  • Workflow Step (text field) – stores the number and label of the step being completed.
  • Workflow Action (text field) – stores the specific action step completed.
  • Event (multiple line text field) – stores details about the action completed.
  • AdminNotes (multiple line text field) – allows me to store specific notes for troubleshooting.

I configure my workflows to write an entry to the WorkflowLog everytime an important step is completed. If the workflow creates a new item and sets the status to ‘Created’, the next action is to create a new item in the workflow log and log that creation. Here is an example of the line item created by my Auto-increment ClientID workflow:

WorkflowName

AutoAssignClientID 

EventOccurred

5/15/2008 2:03 PM 

WorkflowStep

1 – Update ClientID then Increment ClientID 

WorkflowAction

Updated the ClientID on the new client 

Event

The workflow has taken the latest ClientID from the SystemCounters database and updated the Customer. Then it has incremented the SystemCounters by one.

AdminNotes

You can see, from the example, that I know that the workflow ran step 1 at 2:03pm on 5/15/2008. I know the step completed, and what it did. The link in the Admin Notes opens the original item so that I can check it. The workflow log allows you to easily troubleshoot a failed workflow – and it has the advantage that it works for Custom Form Actions (which have no history at all?).

Organising the Log

The log continues to compile workflow entries in the background as my users continue to work in the application. I can sort the log by the date the event occurred or by the workflow name, etc. I also have another field, specific to my company, which contains the “ticket number”. I can sort the workflow log by the specific ticket number, then the workflow name, and then the date and time. I have an admin page that contains a multiple item dataview of the log and allows me to select the ticket number from a drop-down list to filter the available entries. 

Future efforts

I am going to add a new column and link to the workflow. I want a column that stores a link to the actual SharePoint workflow history. If you open the workflow history on an existing item, the URL in the address bar looks like this:

http://mysharepointsite/sites/main/_layouts/Workflow.aspx?ID=72&List=B65934BA-EBF4-4CB8-956D-B0Ce4236B657 

The ID number identifies which specific entry the workflow was run on and the List number identifies which list the entry resides in. I will create a hyperlink that takes the ID from the current item (Dataview) and substitutes the List number as a variable as well.

I think that this log process contains a lot of untapped potential and I will be updating this post as I add to the log.

UPDATE

Paul Galvin pointed out that I forgot to mention some  of the possible downfalls to this logging method. You can see his blog here

Thanks for Reading

May 16, 2008 at 1:31 pm 8 comments

Create a Virtual Time Card System

Disclaimer: I found this tip on the web in a forum or site – but I can’t remember/locate the original source. If anyone knows the original source, please let me know.

I haven’t attempted this yet, and I would probably add some more detail to the instructions – but I want to get the basic idea up on the blog so I don’t lose the piece of paper I scribbled it on.

The Basic Scenario

The user clicks a button to “punch in” when the start work. The button creates a new item in a list and the system records the UserName, Time, Date, Department and TimeIn.

At the end of the workday, the user clicks the “punch out” button. The button creates a new item in a different list and that launches a workflow that edits the original item and recrds the UserName, Time, Date, Department and TimeOut. The workflow then populates a rich text field with the contents of both items.

At the end of the week, compile the contents of all of the records for all of the days of the week into one rich text field for the manager.

My Updates

Can the punch in process not be automated? When the user opens the Intranet Home page – you can grab the user logon credentials from server variables and then create the item automatically?

Instead of a rich text field with all of the records dumped into it, a multiple item dataview which is filtered by a drop-down (select username) would be much more organised.

Add an approval process and allow the manager to email the approved timesheets to the HR department – or send unapproved timesheets back to the original users to correct any mistakes. 

 

May 14, 2008 at 2:28 pm Leave a comment

Design Tip 4: Turn Any Field in a Dataview into a Hyperlink

Any field in a Dataview (single or multiple item view) can be converted into a hyperlink to allow users to jump to the item in detail.

In one of the web applications I have created, the main page shows a customised multiple item Dataview that allows the user to see all of the currently open tickets and the status they are in. There are columns for Ticket Number, Edit Ticket, Comment, etc.

The Ticket Number is a hyperlink field that takes the user to a customised Dispform.aspx page where they can see a read only version of the ticket details. The Edit Ticket column contains hyperlinks to a customised Editform.aspx. The Comment column has hyperlinks which take the user to a customised Newform.aspx page to enter comments (in a different list).

The one thing that all of the lists in the application have in common is the Ticket number field. The hyperlink for the Comment column looks like this:

<a href=”http..sharepointsite/lists/newform.aspx&Ticket={@Title}” OnClick=”GoToLink(this);return false;”  target=”_self”>Comment</a>

Because the hyperlink is contained within a Dataview, you can access the variables from the dataview. The system will place the “Title” field value into the URL for the ticket I am clicking on. If I click the Comment hyperlink on ticket 12, it will place a 12 in the URL. The target form uses a Query String to access the Ticket variable and the new Comment is created for that ticket.

Click here to learn about defaulting values on a new item form:

https://splittingshares.wordpress.com/2008/04/22/defaulting-a-hidden-field-on-a-form/

May 14, 2008 at 2:15 pm Leave a comment

Design Tip 3: Custom Actions on Form Buttons are just like Workflows

Form buttons can have Form Actions associated with them. Form Actions can contain Custom Actions. Custom Actions in Form Actions are configured just like workflows – the main difference is that they don’t initiate until the button is pushed. 

I have been moving a lot of my workflows into Custom Form Actions. I like the fact that they only get started when the button is pushed. For example, when a user edits a specification in my web application and clicks Save, the Custom Form Action checks the current status of the specification. If the specification was in Created status, it saves the specification and changes the status to In Progress. If the specification was in Review status, it emails all of the Reviewers to let them know it has been changed and then sets the status back to In Progress.

Important: I have come across one major problem using this tip. The Custom Form Actions don’t seem to have a workflow history. There is no way, that I can find, that allows me to see when the Custom Form Action ran, where it got stuck and what the current status is. This can be a nightmare when trying to troubleshoot any issues.

Workaround: I have created a custom list to track workflow statuses. After a workflow completes any step – I have it write to the custom list – this way when a workflow or custom form action fails, I can check what the last correct step was. I think that I will post a more in-depth topic on logging workflows.

May 14, 2008 at 2:13 pm 6 comments

Design Tip 2: Deleting and Restoring a List Item destroys Workflows

I had several workflows in my web application that would start when a new item was created and then pause for a duration or wait for a field to change. The user would create an item, the workflow would start and then it would wait for the status field to equal Completed.

If you delete the list item, in my case it was by accident, and then restore the list item, the workflow remains in the waiting status forever.

Hopefully someone with some real in-depth SharePoint knowledge reads this and they can explain why it behaves this way?

May 14, 2008 at 2:12 pm Leave a comment

Design Tip 1: Hyperlinks Should Always Contain the Source

This tip was taken from SharePoint Online Help Topic – Return your Customer Back to your Data View

Original topic: http://office.microsoft.com/en-us/sharepointdesigner/HA102403641033.aspx

When a user clicks ANY link in a web application I have created, the URL passed to the new page contains the source location the user came from. If you examine the URL in the default lists and items in SharePoint, you will notice that they almost always contain the ‘&Source’ variable.

Why?

If the URL contains the source, you can use it in a Query String variable or in a Navigate to Source Form Action. You will be able to control how a user moves through your web application and therefore control the user’s actions and perceptions in the application. If you control there perception in the web application, there is nothing you cannot do.

When a user clicks the Create New Item link on a page on my site, they will be redirected to the Newform.aspx page I have customised (the page could be called anything because I control where the hyperlink points). But, when the user clicks Save or Cancel on the new form, where is the user sent?

I like to have the user automatically redirected to the next step, or sent back to the page they came from.

Add the code to the Hyperlink

Hyperlinks should contain the following attributes in the <a> tag to let the system know which page the user came from. A normal hyperlink might look like the following:

<a href=”http://..mysharepointsite/folders/link…”>link text</a>

In order to enable the source variable in SharePoint, all you need to add is the following attributes:

OnClick=”GoToLink(this);return false;”

target=”_self”

The new hyperlink would look like this:

 <a href=”http://..mysharepointsite/folders/link…” OnClick=”GoToLink(this);return false;”  target=”_self”>link text</a>

When the user clicks the the new link text, the target page will open and the URL in the address bar will contain the ‘&Source’ variable.

Put that Information to Good Use

The URL now contains a variable for the user’s source page, so what? How do I leverage this new found super power?

Form Buttons

If you right-click on a form button (for example, the Save or Cancel button), you will see an option for Form Actions in the pop-up menu. Select Form Actions and you will open the Form Actions dialog box. You can now add the Navigate to Source action to the button and when the user clicks it, the button will perform it’s action (for example, Commit or Cancel) and then return the user to the page they came from.

May 14, 2008 at 2:10 pm Leave a comment

SharePoint Contact Lists play nicely with Outlook

Contact Control

I was designing an application in SharePoint and I wanted to create a custom list for storing company contacts – one for internal contacts and one for customers. I wanted to have full control over the contact list and set out creating all of the fields from scratch in a custom list. After about a week of using the new list, a user asked me if they could link the list to Outlook to have the address books automatically synchronized…

That’s when I realised what I had done wrong.

We Digress…

We don’t use MS Exchange in our office. We use a third pary mail system. Needless to say, we sacrifice a lot of built in functionality that we would otherwise be able to leverage. Is Bob available for a meeting next Tuesday? If his calendar availability was published in Exchange then I could check it… But, that’s a rant for another day.

Outlook Functionality for Free

If you create a contact list in SharePoint using the default Contacts list template, you get built in functionality with SharePoint-services compatible contact programs. And which program is number one on that list? MS Outlook.

I created a test contacts database using the default contacts template. When you open the list, there is a Connect to Outlook option in the Actions menu. If you click it, Outlook pops-up (it was already running), and asks me if I want to connect the specified SharePoint Contact list to Outlook.

Needless to say, I was quite happy with this instant functionality. No code, no programming, nothing from me – and ‘poof’ everyone in the office is running around syncing contacts and calling me and SharePoint the best things since USB Humping Dogs!!

I guess the point of this topic is to save some other poor SharePoint Designer from being destroyed by their own ego. Don’t reinvent the wheel. Just hop on and enjoy the ride!

Thanks for Reading

 

May 14, 2008 at 12:41 pm 2 comments