Introduction

The latest How To topics are available in the K2 Five User Guide or the K2 Cloud User Guide’s How to section.

Query String parameters can be sent to a Form in SharePoint by using a content editor web part. This Knowledge Base article describes how to configure a Form with parameters to enable Query String parameters in a Form in SharePoint.

Implementation Details

Follow the steps below to implement the scenario as described above.

  1. For purposes of this article a simple Form was created in K2 smartforms.
    Image
  2. Add parameters as shown below:
    Image
  3. Add the following Rule on the Param1 control:
    Image

    With the following configuration:

    Image
  4. Add an expression on the Param 2 control as shown below:
    Image
  5. Finish the Form, then click on Run with parameters. Provide values for the parameters and click Run. Note the parameters added to the URL.
    Image
  6. The Form is opened and the expression is applied to Param2.
    Image
  7. In SharePoint, add a Content Editor Web Part, edit the HTML and paste the following. The URL will be the URL used for the Form created.

     

    <iframe width="100%" height="100%" id="targetForm" frameborder="0"></iframe>

    <script>

    document.getElementById("targetForm").src="http://dlx:81/Runtime/Runtime/Form/Parameters/" + location.search;

    </script>

     

    For more information on how to add a Content Editor Web Part, see KB001348.

  8. Apply the parameters in the URL of the SharePoint site and see how the expression is applied here as well.
    Image
  9. If you would only like to pass certain query string parameters to the Form then replace the following script in the Content Editor Web Part:

     

    <script>

    document.getElementById("targetForm").src="http://dlx:81/Runtime/Runtime/Form/Parameters/" + location.search;

    </script>

     

    With the following:

     

    <iframe width="100%" height="100%" id="targetForm" frameborder="0"></iframe>

    <script language="javascript">

                var qParamsCol = location.search.substr(1).split("&");

                var iparam;

                var newURL = "http://dlx:81/Runtime/Runtime/Form/Parameters/?";

                var addAmbersand = false;

                for(iparam = 0;iparam < qParamsCol.length;iparam++)

                {

                    var sparam = qParamsCol[iparam];

                    var sparamName = sparam.substr(0,sparam.indexOf("="));

                    switch (sparamName)

                    {

                        case "Param1":

                        case "Param2":

                        {

                           if (addAmbersand)

                            {

                                newURL += "&";

                            }

                            newURL += sparam;

                            addAmbersand = true; //All parameters after this require '&'

                        }

                    }

                }

                document.getElementById("targetForm").src = newURL;

            </script>

     

    Update the switch() case statement to include each parameter that you would like to pass in:

    Example:

     

    switch (sparamName)

                    {

                        case "Firstname":

                        case "Lastname":

           case “ID”:

                        {