This article is step by step guide how to populate PDF forms with data form External list. For the purpose of this guide, we have prepared the following External Content Type:

(Click on the image to view it in full size)

Assuming “ADDRESS” field is unique, we can identify an External list item through that field.

Step 1. Prepare template with custom server “Form Load” action.

Add the following script to a “Form Load”event:

try 
{
	if (form.IsNew()) 
	{
		string key = form.GetQueryParam("itemID");
		string entityNS = "http://pdemo";
		string entityName = "TESTBASE2";

		using(BCSAccessor accessor = new BCSAccessor(currentWeb.Site, entityNS, entityName))
		{
			DataTable dt = accessor.FindItems("Read List");
			DataRow row2 = dt.Select("ADDRESS Like '" + key + "'")[0];
			data.resolveNode("TextField1").value = 
				row2["ADDRESS"].ToString();
			data.resolveNode("TextField2").value = 
				row2["FIRST_NAME"].ToString();
			data.resolveNode("TextField3").value = 
				row2["LAST_NAME"].ToString();
		}
	}
//this part is to help you with debugging
} catch (Exception ex) {
	data.resolveNode("TextField3").value = ex.Message;
	data.resolveNode("TextField4").value = ex.StackTrace;
}

Step 2. Prepare custom action.

First, we need to deploy our PDF form to a specified folder.

Note: There is information about exception in TextField3 and TextField4.

Then we need to copy the URL of new document. This can be made by opening Documents > New documents > Our Content type name.

Next step is to create new custom action in Central Administration for our External Content Type, and we will call it “Start Review”

In the “Navigate to this URL” field, add the copied URL, followed by&itemID={0}. Then add parameter “ADDRESS” to URL “Parameters section”. In the end the URL should be similar to this:

http://pdemo/_layouts/PDFForms/PDFFormRender.aspx?List=[custom]&RootFolder=[custom]&ContentTypeId=[custom]&Source=[custom]&itemID={0}

Step 3. Create External List in your Library and test custom action.

This is how External List appears in Library:

Once “Start Review” action is assigned, clicking on our a specific list item will open a new PDF form and the corresponding list data is contained in it:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.