In this post we will discuss about how how we can change to different views in infopath form based on certain condition in SharePoint 2010. Also you can check my previous posts on:
Suppose an employee send a leave request in a company. Then the request may go to Team leader, HR etc. So whenever an employee open the infopath form he should see his information relevant to him, Similarly Team leader should see the relevant information to team leader. And similar case with HR also. So in this type of scenarios we will create different views in infopath, one view for employee, one for team leader and one for HR. Follow below steps:
1. Activate SharePoint server enterprise site collection features
2. Create the needed users
3. Create your custom list with following columns.
4. Now click on list tab-> customize form on the ribbon to create multiple views.
5. Now it will open your list in infopath form.
6. Now we will remove the unwanted columns – Title,Attachment,Action,State.
7. Click on PageDesign -> New view -> give the name of the view – Employee view, Team leader view.
8. Then copy the edit view and paste in your Employee view.
9. Keep the desired fields and delete the rest.
10. Add two button for submit and cancel. Home->Control->Button.
11. Now do same for manager view. Here three button- Approve, Reject, Cancel.
12. Then we will add rules for switching views.
13. Click on Data Tab -> Form load -> New -> Action -> Type Show employee view -> condition -> status is blank -> switch views -> Employee view. see fig below
14. Do same to show TL view. Only add the condition as status -> is equal to -> WaitingTL. see fig below
15. Now go to Employee view -> submit button -> New -> Action -> Give name as SubmitEmployee-> Add-> set field value:Action= SubmitEmployee -> submit data using data connection -> close the form
16. Cancel button -> new -> name :cancelemployee -> add -> close form
17. Go to TL view -> Appove button -> New -> name :ApproveTeamLeader -> set field value: ApproveByTL-> Submit data -> close form.
18. Do same for reject button only change the set field value as RejectTL.
19. Cancel button has same rule as in Employee view.
20. Now save and publish the infopath form.
21. Now go to your list and add new item.It will show you the employee view.
22. Here you fill the details and submit.
23. Click on datasheet view from ribbon and change the status to WaitingTL.
24. Now come to your item. Click on the item it will show you the TL view. And here you can approve the employee.