Adding custom logic using C# rules

One of the most powerful ways to customize PDF files is by using C# Script. C# code is executed while processing the form, so this type of scripting is performed only at the server side.

Scripting context gives access to current SharePoint context and form data, which allows pre-generating / or post-updating form values or interfacing some third-party systems.

Publishing form with server side scripts requires user to be a member of Script Deployment Group permission group (Set up in Central Administration → PDF Share Forms Information Worker Settings → Permissions)

Specify all user who can deploy PDF templates with C# script code and click Save.

To use C# scripting, open a template and navigate to the Options → Rules under the Server Rules tab find preferred script execution method

C# code can be tied to a specific PDF server-side event - On Load, On Sync or On Submit.

In order to start adding C# script Execute script action should be added to an event. Following steps shows how Execute script action can be added into On Load event:

Step 1. Click on the red line under Execute system On Load action and choose Action

Step 2. Then choose Execute script

Action appears in event rules window


Click on Click to edit scripts...

Step 3.  User can start adding script

After script is added, user can check if it contains error by clicking Compile and then Save.

Following contextual variables are available in scripting:

  • ScriptingData data
  • ScriptingContext context

Scripting Examples

  • Set field “CurrentUser” value to current SharePoint user name: data.ResolveNode("CurrentUser").Value = context.SystemData.CurrentUser.Name;
  • Set default value if form is new:
    if (context.SystemData.IsFormNew) {
         data.ResolveNode("TextField1").Value = "some default value";

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


Please sign in to leave a comment.
Powered by Zendesk