Follow

Duplicating and deploying templates by web services

Applies To: Information Worker for SharePoint 2013/2016

 

PDF Share Forms provides web services that allow to retrieve and update PDF forms data and template. Article describes how to use web services to duplicate existing template (that contains DataSources) and deploy to specific SharePoint library, on specific site.

 

Web Services

Web Services can be accessed from the following site: http://yourWebSiteUrl/_layouts/15/pdfsf/services/DesignerService.asmx

  • DuplicateTemplate (templateName, newTemplateName, userLogin) - duplicates specified template and sets duplicate’s name.
    Parameters:
    • templateName – name of a template that must be duplicated;
    • newTemplateName – name of a duplicated template (we suggest using templateName_<siteCollectionName> in order to ease sorting);
    • userLogin – user who has permissions on a source and target site collections.
  • UpdateListDataSource(templateName, existingDataSourceName, dataSourceListName, webUrl, userLogin) - if duplicated template contains datasources, they must be updated in order to take data from correct lists on a new site collection.
    Parameters:
    • newTemplateName – name of a duplicated template;
    • newWebUrl – site collection URL where duplicated template is created;
    • existingDataSourceName – name of a data source to update (from original template);
    • dataSourceListName – name of a SharePoint list, from which data source takes information;
    • userLogin – user who has permissions on a source and target site collections.

  • DeployTemplate(templateName, targetListName, contentTypeName, webUrl, userLogin) - deploys duplicated template to the destination site collection, specifies forms name and target library.
    Parameters:
    • newTemplateName – name of a template that must be deployed;
    • newWebUrl – URL of a site collection where template must be deployed;
    • contentTypeName – new content type name;
    • targetListName – SharePoint library name where new content type must be published;
    • userLogin – user who has permissions on a source and target site collections.Example for your case is almost ready and will be available tomorrow.

Usage example

Following Console Application was created:

        static void Main(string[] args)
        {
            EndpointAddress endpoint = new EndpointAddress("http://yourURL/_layouts/15/pdfsf/services/DesignerService.asmx");
            DesignerServiceSoapClient client = new DesignerServiceSoapClient(getBinding(), endpoint);
            client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            //this user will be used to duplicate, update and deploy templates
            client.ClientCredentials.Windows.ClientCredential = new NetworkCredential(
                   "john",
                   "somePass",
                   "dev"
                   );
            //referring to required templates and properties
            var templateName = "Original Template Name";
            var newTemplateName = "New Template Name";
            var listName = "Publishing Target Library";
            var newListName = "List that populates Data Source";
            var newContentTypeName = "New Content Type Name";
            var existingDataSourceName = "DataSource name from the original template"; //it will be updated in specified template
            var newWebUrl = "http://sp201304/sites/site_a/subsite_b";
            //calling web services
            var res1 = client.DuplicateTemplate(templateName, newTemplateName, null);
            var res2 = client.UpdateListDataSource(newTemplateName, newWebUrl, existingDataSourceName, newListName, null);
            var res3 = client.DeployTemplate(newTemplateName, newWebUrl, newContentTypeName, listName, null);
        }

 

Adding references

In order to add references to the web service in your project, follow this steps:

Step 1. Right-click on Service References → Add Service Reference...

Step 2. Specify Web Service address and click Go. When Web Services are found, specify namespace and click OK

Runtime

One site collection and one subsite were created: http://sp201304/sites/site_a and http://sp201304/sites/site_a/subsite_b. Both sites have similar deployment target libraries (Request Forms) and similar SharePoint list (Employees) that will be used to populate a data source.

Original template is created on the site_a. This template is published to Request Forms document library, it contains DataSource that retreives information from Employees list and populates dropdown field. This template and its' content will be duplicated and published to the http://sp201304/sites/site_a/subsite_b by using PDF Share Forms web services and SharePoint console application.

Step 1. http://sp201304/sites/site_a site collection contains "Employees" list that populates data source in a form and "Request Forms" library (target SharePoint library where forms will be stored).

Step 1.2  Navigate to My Form Templates. We have a template prepared:

Template is published to http://sp201304/sites/site_a site collection into "Request Forms" library.

Step 1.3 Open the template. It contains dropdown field and text field

Dropdown field - Employee is populated from by data source that takes information from "Employees" list (step 1).

Step 1.4 Data Source configurations can be found by navigating to Options tab → Data Sources

Data Source is called "EmployeesDS" and takes information from "Employees" SharePoint list.

Step 1.5 Navigate to Designer tab and select the dropdown. Navigate to Properties Dropdown Items

Drpdown is set to take information from EmloyeesDS DataSource, from "Employee Name" column.

Step 1.6 After publishing the template, form's runtime can be seen below:

Step 2. Open SharePoint Console Application. In our case it look like following:

 static void Main(string[] args)
        {
            EndpointAddress endpoint = new EndpointAddress("http://sp201304/_layouts/15/pdfsf/services/DesignerService.asmx");
            DesignerServiceSoapClient client = new DesignerServiceSoapClient(getBinding(), endpoint);
            client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
            //this user will be used to duplicated, update and deploy templates
            client.ClientCredentials.Windows.ClientCredential = new NetworkCredential(
                   "john",
                   "somePass",
                   "dev"
                   );
            var templateName = "Request Example Form";
            var newTemplateName = "Request Example Form_" + RandomString(5);
            var listName = "Request Forms";
            var newListName = "Employees";
            var newContentTypeName = "Request Example Form_" + RandomString(5);
            var existingDataSourceName = "EmployeesDS";
            var newWebUrl = "http://sp201304/sites/site_a/subsite_b";

            var res1 = client.DuplicateTemplate(templateName, newTemplateName, null);
            var res2 = client.UpdateListDataSource(newTemplateName, newWebUrl, existingDataSourceName, newListName, null);
            var res3 = client.DeployTemplate(newTemplateName, newWebUrl, newContentTypeName, listName, null);
        }

Step 2.1 Run you application. New duplicated template appears in MyForms

Step 2.2 Navigate to http://sp201304/sites/site_a/subsite_b/Request Forms library and open a new form

Dropdown is populated with different values, since subsite_b "Employees" list contains different values.

Step 2.3 Forms is successfully submitted

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk