Tuesday, October 19, 2010

Other methods to get the Content Type ID

Following the last post where I discussed the different methods of getting the GUID for list and ID of content types, there are other ways to get the content type ID.
If you have SharePoint Designer, you can navigate to the content type section, and then select any content type. The content type page will contain the Hex format of the ID for that content type. Unfortunately, using this method will not provide the GUID for the fields used in this content type.
Another way to get the ID for a content type, is to navigate to the features folder on the server
(drive://Program Files /Common Files/Microsoft Shared/Web Server Extensions/ 14/Templates/Features/ (select the list or content type folder)
When you open the schema.xml file you will be able to get the GUID for the content type as well as every field used in this content type.
For example this is the GUID for the event content type
As you have seen above, there are two formats to define the ID of a content type, the Hex code and the GUID.
 















To define a new content type, you must inherit form an existing content type which enables you to inherit all columns, workflows any information policy attached to the parent content type. The new Hex ID for the new content type will be composed of the Parent Content Type ID + 2 Digit Hex Value. If you are using the Guide format, as recommended by Microsoft as best practice, the GUID will be composed of the Parent Content Type ID + 00 + GUID (without any special characters) for example, a content type that inherits from the event content type will have GUID
01x0102DE7CA8F1-A8B0-490F-913D-F0F60638A18F
Where the 01x102 is the event ID (the parent) then a GUID {DE7CA8F1-A8B0-490F-913D-F0F60638A18F} with the {} removed.

Getting the GUID or internal field names of items in SharePoint

Many times during developing a SharePoint solution, we need to get the GUID of a list item, content type or a field but SharePoint does not display these GUIDs in an obvious way. In this post, I will discuss two ways that you can use to get the GUID of these items to be used during development.
One way to get the GUID is simply to navigate to the list settings page, copy the url, it will look like this:
http://YourServerName.com/_layouts/listedit.aspx?List=%7BEEF4F8B7%2D27D4%2D4A81%2D9E51%2D6A588EEF8D94%7D

The string after the List= is the encoded GUID i.e.
%7BEEF4F8B7%2D27D4%2D4A81%2D9E51%2D6A588EEF8D94%7D is the encoded GUID. Now you need to decode the GUID using one of these online tools (There are many resources online for encoding and decoding URLs that can do the same trick as well)

http://urldecoderonline.com/ (The is the best tool because you can copy the entire URL and it will break the URL to its complements which provides you with the list item very easily)
the decoded URL will look like this:
http://YourServerName.com/_layouts/listedit.aspx?List={EEF4F8B7-27D4-4A81-9E51-6A588EEF8D94}
so the list GUID is {EEF4F8B7-27D4-4A81-9E51-6A588EEF8D94}
To get the ID of a content type, navigate to the content type in the site content type gallery copy the string after the ctype of the URL and decode it, again, using one of the above tools. For example,
http://YourServerName/_layouts/ManageContentType.aspx?ctype=0x0107&Source=http%3A%2F%2FYOURSERVERNAME%5Flayouts%2Fmngctype%2Easpx
Encoded Content Type ID  0x0107
Decoded   Content Type ID  258
You can also apply the same technique to get the internal names of fields by using the string after the Field=
http://YourServerName.com/_layouts/fldedit.aspx?field=WorkPhone&Source=%2F%5Flayouts%2Fmngfield%2Easpx%3FFilter%3DAll%2520Groups


Tuesday, October 5, 2010

Using InfoPath and SharePoint Workflow: Create a task link to open the form in the browser.


One of the options that developers have while working with SharePoint is to use InfoPath forms and custom workflows. Another advantage is the ability to use InfoPath to integrate with SharePoint to provide a riche web forms that can be configured to enhance the user’s experience by setting default values and using filtering and views. The challenge in this scenario is not in the ability of handling the forms on the server (which is managed by the SharePoint when using web enabled forms) but with how the user who does not have InfoPath client installed interacts with the task e-mails sent for the workflow tasks. For example, look at the first link in the e-mail and you will quickly notice that it has an .xml extension.

If a user clicks on the link, the form will be downloaded and if the user does not have InfoPath installed on the machine, then the user will not be able to review the document.

In the following text, I will provide a very simple solution to this problem so that the user is presented with a link that opens the form on the server directly.

Here are the general steps involved:

1- We will create a custom task list to separate any tasks created by the work flow from other site tasks.
2- Go to the custom task list you created in step 1 and disable the custom task sending the e-mail
List settings --> Advanced settings then under E-Mail Notification

3- Select No for send e-mail when ownership is assigned?
 

4- Create a workflow that sends the e-mail notification for the form.
Below is a sample workflow I created for this demo:
The first action in the workflow is to create a variable to the URL of the form. To do this, select set workflow variable from the Actions menu.

5- On the variable name, select create a new variable and give it a name, in this case I named the variable FormURL.
6- In the value part of the action, click the Formula button and set the values of the look up as shown below:
Data Source: Form Library (the name of your form library)
Field from source: Encoded Absolute URL

In the “Find List Item” Section of the look up, select:
For the field: ID
Value: click the Formula button, and then set the values to:
Data Source: current item.
Form From Source: Workflow Item ID.

What we have done in this look up is to get the absolute URL for the item in the form library by whose ID matches the custom task list that has the matching Item ID.
The lookup should look like the figure below:

To explain this, when a task is created in a task list, the workflow adds 3 fields to the task
Workflow Item ID (the ID of the item that the workflow was initiated from- in this case the form item)
Workflow List ID (the ID of the List where you can find the item that the workflow was initiated from
-in this case the form library)
Workflow name: The name of the workflow that created the task in the task list

7- Once you have set up the variable as shown in the figure, you have the URL of the specific item you need.
8- Next, add send e-mail action (do not configure it now, we will configure it later)
9- Now open a form from your form library and copy the URL from the browser address
The URL will look like this:

10-Now remove the section in red (between location=) and (source) and add
Name of document to create a hyperlink using the document name.
11- And add [Document URL look up] instead. The code should look like the lines below:

12- Now, go to the send e-mail action that you created before and select it (do not double click to open it)
13- Once it is selected, go to the ribbon and select advanced properties

14-Select the body by clicking the button as shown below

15-Paste the code from the note pad
16-Replace the [Document URL look up] by selecting the text then click the ADD or Change Lookup button.
17-In the Lookup, select Workflow variables and parameters as the data source and the FromURL variable you created earlier.
18-Now the final step here is to replace the Name of document with a look up to the document name as follows:

Data Source: Form Library (the name of your form library)
Field from source: Name
In the “Find List Item” Section of the look up, select:
For the field: ID
Value: click the Formula button, and then set the values to:
Data Source: current item.
Form From Source: Workflow Item ID.

As you noticed, the setup is the same as the first look up but this time we selected the Name from the Form Library.

19-Now, set up your workflow to start automatically when Item is created.

You can customize your e-mail further and add company logo or any other html formatting that you need.