You may be familiar with SharePoint
workflow, but have you added workflow to an InfoPath template? InfoPath
workflow is easier to use because it's handled in InfoPath instead of requiring
the user to complete certain actions in SharePoint.
Users can easily see the state of the form
and you can add custom conditional viewing to switch views based on the user
role (e.g. a private Comments section
in a Manager's view).
During this lab, you will modify a
Timesheet form template to pull user information from Active Directory, submit
to SharePoint, and pass the SharePoint link in the notification email.
Retrieving the Users' Active Directory Information
If you go to Data > Data Connections, you'll see the pre-configured data
connections that use Qdabra DBXL's Active Directory Web Service methods to
retrieve the users' information.

And if you go to Data > Form Load, you will see a rule that populates the user
info:

We're basically setting the fields in our
form to the values retrieved from the Active Directory web service methods and
using filters to specify which Key to
use.
Add the Submit Data Connections
Start by modifying the starter template to
add data connections that submit the form to SharePoint and through email.
1.
Open the Starter Template XSN
(included in this lab) in InfoPath Designer.
2.
Save the template on your local
machine by going to File > Save As and
saving it with the name Timesheet.xsn
3.
Add the data connection to
submit to your SharePoint library.
a.
Go to Data > Data Connections
> Add > Create a new connection to
submit data > To a document library on a SharePoint site
b.
Enter the name of your document
library, such as http://training.qdabra.com/personal/<<username>>/
c.
For the File Name, click on the
fx
button and insert the formula:
concat(tc:week/tc:weekOf, " - ", tc:employee/tc:name/tc:singleName)
If you click on the Verify
Formula button, you should see the following:

d.
Click OK in the Insert Formula dialog.
e.
Check the box ‘Allow overwrite
if the file exists'.
f.
Click Next, leave the default data connection name, and then click Finish.
4.
Add an email submit data
connection.
a.
In the Data Connections dialog, click Add
> Create a new connection to submit data > As an email message
b.
Click on the fx button
next to the To field and select the emailto field which you'll find under
the my:actions group in the main data
source.

c.
Click on the fx button
next to the Subject field and enter
the formula:
concat("Time
Card: ", tc:week/tc:weekOf, " - ",
tc:employee/tc:name/tc:singleName, " has been ",
my:actions/my:status, " by ", my:actions/my:modifiedby,
".")
If you click on the Verify
Formula button, you should see the following:

d.
Click OK in the Insert Formula dialog
and then click Next.
e.
Make sure that the option ‘Send
only the active view of the form and no attachment' is selected.
f.
Click Next, leave the default data connection name, and then click Finish.
5.
Click Close to exit out of the Data
Connections wizard.
Add the Rules that Trigger the workFlow
In the Employee
(default) view, you'll see a Submit
button. This button will have rules that will set the form fields' values that
are being used in the workflow, such as who modified the form, whom is it
assigned to after the form submits, which email address should it be sent to,
etc. Same goes for the Approve and
the Reject buttons which you'll find
in the Manager view - they have rules that trigger the workflow.
Since the form also has a Form History
section for tracking purposes, you may find other rules that set the history
data. These have already been added in the form so we can concentrate on implementing
the logic that is associated with the workflow.
Start by modifying the Submit button:
6.
In the Employee view, click on the Submit
button.
7.
From the Home tab > Rules
section, click Manage Rules to display the Rules taskpane.

You will see the
following pre-configured rules:

8.
Add a rule that sets the
metadata
a.
In the Rules taskpane, click New
> Action.
b.
Name your rule ‘Set Metadata'.
c.
Move the rule up so that it's
the third in the set, i.e. after the rule ‘Warn: Need Hours'.
d.
Set the modifiedby
field:
i.
Click Add > Set a field's value.
ii.
For the field, select modifiedby under the my:actions group:

iii.
For the value, click on the fx button
and select singlename under employee > name

You can also
just enter the following XPath in the Insert
Formula dialog: tc:employee/tc:name/tc:singleName
iv.
Click OK to close the dialogs.
e.
Set the assignedto
field:
i.
Click Add > Set a field's value.
ii.
For the field, select assignedto under the my:actions group.
iii.
For the value, click on the fx button
and select singlename under employee > name.
iv.
Click OK to close the dialogs.
f.
Set the emailto field:
i.
Click Add > Set a field's value.
ii.
For the field, select emailto under the my:actions group.
iii.
For the value, click on the fx button
and select emailAddressPrimary under
company > contact. You can also
just enter the following XPath in the Insert
Formula dialog: tc:company/tc:contact/tc:emailAddressPrimary
iv.
Click OK to close the dialogs.
g.
Set the status field:
i.
Click Add > Set a field's value.
ii.
For the field, select status under the my:actions group.
iii.
For the value, enter the text Submitted
iv.
Click OK.
h.
Set the notes field:
i.
Click Add > Set a field's value.
ii.
For the field, select notes under the my:actions group.
iii.
For the value, enter the text Submitted to Manager
iv.
Click OK.
You should now
have the following Submit button
rules that set the metadata:

9.
Add a rule that submits the
form:
a.
Click New > Action.
b.
Name your rule ‘Submit' - this
will be the last rule in the set.
c.
Submit to SharePoint:
i.
Click Add > Submit data.
ii.
Select your SharePoint Library submit
data connection from the drop-down:

iii.
Click OK.
d.
Set the done field:
i.
Click Add > Set a field's value.
ii.
For the field, select done under the my:actions group.
iii.
For the value, enter 1
iv.
Click OK.
Notice the
conditional formatting in the Submit button:

This means that
we want the Submit button to be
disabled if the value of the done field equals "1" which we set after
the form submits to SharePoint. This will prevent users from clicking on the Submit button twice which may result to
double-submits.
e.
Submit via email:
i.
Click Add > Submit data.
ii.
Select your email submit data
connection from the drop-down.
iii.
Click OK.
f.
Close the form:
i.
Click Add > Close the form.
ii.
Uncheck the box ‘If changes
have not been saved, prompt the user to save.
iii.
Click OK.
You should now
have the following Submit button
rules that submit the form:

Next, we will add rules in the Approve button:
10.
Go to the Page Design tab and switch to the Manager view.

11.
In the Manager view, click on the Approve
button. You will see the following pre-configured rules:

12.
Add a rule that sets the
metadata.
a.
In the Rules taskpane, click New
> Action.
b.
Name your rule ‘Set Metadata'.
c.
Move the rule up so that it's
the second in the set, i.e. after the rule ‘Warn: Need Notes'.
d.
Add the following actions:

13.
Add a rule that submits the
form:
a.
Click New > Action.
b.
Name your rule ‘Submit' - this
will be the last rule in the set.
c.
Add the following actions:

Finally, we'll add rules for the Reject button:
14.
In the Manager view, click on the Reject
button.
15.
Add the same ‘Set Metadata'
rule that runs after the ‘Warn:Need Notes' rule.
16.
Add the following actions:

17.
Add a Submit rule which is the last in the set, and then add the
following actions:

18.
Save your changes to your XSN.
Create the Form Link
We will add a hyperlink control that links to
the form in SharePoint. The link will be included in the notification email so
that users can click on it to open the form.

19.
In the Manager
view, you'll see a small section at the bottom. Place your cursor below the
label ‘Click here to open this time card:'

20.
Go to the Insert
tab and click Hyperlink.
21.
In the Insert
Hyperlink dialog, change the Link to and the Display options to Data Source.
22.
Insert the formula:
concat(substring-before(substring-after(/processing-instruction()[local-name()
= "mso-infoPathSolution"], 'href="'), "/Forms/"),
"/", tc:week/tc:weekOf, " - ",
tc:employee/tc:name/tc:singleName, ".xml")

The formula is a concatenation of the form
location in SharePoint, e.g. http://<YourSharePointSite>/<YourSharePointLibrary>/<FormFileName.xml>
Recall that we've
set the form file name to this formula on SharePoint submit:

Publish the Template to your SharePoint Library
In order to access the form template and submit
forms, you need to publish it to a location where users can access it from,
such as a SharePoint form library.
23.
Go to File > Publish and then select SharePoint Server.

24.
Enter the URL to your
SharePoint site.
25.
Leave the default to Form Library and then click Next.

26.
Select ‘Update existing form
library' and select the SharePoint library you created earlier - that is, where
you've set your forms to submit to.
27.
Click click Next twice, click Publish, and then click Close.
Test by submitting a new Timesheet form assigning it to your
manager. Your manager will receive the form via email and will see a link where
to access the form.

The manager will then open the form via the
link and will decide whether to approve or reject. Approving goes to HR and
rejecting goes back to the original submitter.
