Switch views - InfoPath Dev
in

InfoPath Dev

Switch views

Last post 06-01-2010 12:29 AM by Prasad. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 05-31-2010 11:27 PM

    • Anshul
    • Not Ranked
    • Joined on 05-19-2010
    • Posts 8

    Switch views

    Hi All I want to automate an appraisal process using InfoPath forms and SharePoint. No database available. I have two different views for the manager and Employee. Now i want to display the manager's form when the manager logs in...and the Employee form to be displayed when the employee logs in. I want to do it without using any database. Please Help.. Regards.
  • 05-31-2010 11:47 PM In reply to

    • Prasad
    • Not Ranked
    • Joined on 04-28-2009
    • Hyderabad
    • Posts 19

    To automate the switching views you need to write a code in the form loading event.

    In the loading event we have an argument called "LoadingEventArgs e", on e we have a method called SetDefaultView(), it takes the view name as input parameter.

    Ex code :-    string strDefaultView = GetDefaultViewName(LoggedInUser);
                        e.SetDefaultView(strDefaultView);

     

     

     

     

    Regards,
    P V V S V Prasad
    Invesco
    MyBolg
  • 06-01-2010 12:16 AM In reply to

    • Anshul
    • Not Ranked
    • Joined on 05-19-2010
    • Posts 8
    How to put this code in the form loading event ??? can you please elaborate it please.
  • 06-01-2010 12:29 AM In reply to

    • Prasad
    • Not Ranked
    • Joined on 04-28-2009
    • Hyderabad
    • Posts 19

    Hi Anshu 

    Before you submit the form store the folloing information in the hidden fields

    • who is the submitter
    • who is the manager ...

    in the load event take the logged in user and compare it with the hidden field values and based on it decide the view name and then use the above code.

    Look at the sample code below to get the default view name:

    private string GetDefaultViewName(string strLoggedInUser, XPathNavigator myRoot)
            {
                try
                {
                    // XPathNavigator myRoot = MainDataSource.CreateNavigator();
                    string strFormStatus = myRoot.SelectSingleNode("/my:myFields/my:Status", NamespaceManager).Value;
                    string strManagerSubmitStatus = myRoot.SelectSingleNode("/my:myFields/my:ValidationFields/my:ManagerSubmitStatus", NamespaceManager).Value;
                    string strApproverDenyStatus = myRoot.SelectSingleNode("/my:myFields/my:ValidationFields/my:SMDDenyStatus", NamespaceManager).Value;
                    string strSubmitter = myRoot.SelectSingleNode("/my:myFields/my:ManagerSection/my:SubmitterAccountID", NamespaceManager).Value;
                    string strReportsTo = myRoot.SelectSingleNode("/my:myFields/my:ManagerSection/my:ReportsToAccountID", NamespaceManager).Value;
                    string strDefaultView = string.Empty;

                    string strAllHRs = myRoot.SelectSingleNode("/my:myFields/my:AllHRContacts", NamespaceManager).Value;
                    bool boolIsHR = false;
                    strFormStatus = strFormStatus.Trim();
                    if (strAllHRs.Trim().Length > 0)
                    {
                        boolIsHR = IsLoggedInUserHRorPayroll(strAllHRs, strLoggedInUser, ',', myRoot);
                    }
                    string strApprover = myRoot.SelectSingleNode("/my:myFields/my:HRSection/my:SMDPicker/my:Person/my:AccountId", NamespaceManager).Value;

                    bool boolIsApprover = false;
                    if (strApprover.Trim().Length > 0)
                    {
                        boolIsApprover = IsLoggedInUserApprover(strApprover, strLoggedInUser, myRoot);
                    }
                    //_ExceptionMessage = (string)_ExceptionMessage + "Submitter:::"+strSubmitter+ "  Repoo rts T:::::"+strReportsTo+"   Form Status:::::"+strFormStatus+ "   Logged in User "+strLoggedInUser;
                    //myRoot.SelectSingleNode("/my:myFields/my:ValidationFields/my:ExceptionMessage", NamespaceManager).SetValue((string)_ExceptionMessage);

                    //If logged in user is submitter or Reports To Manager
                    if (strSubmitter.Trim().ToLower() == strLoggedInUser || strReportsTo.Trim().ToLower() == strLoggedInUser)
                    {
                        if ((strFormStatus.Trim() == "Draft" || strManagerSubmitStatus == "1") && (strFormStatus.Trim() != "Complete" && strApproverDenyStatus != "1"))
                        {
                            strDefaultView = "Manager View";
                        }
                        //If logged in user is submitter or reports manager as well as HR
                        if (strManagerSubmitStatus == "1" && boolIsHR)
                        {
                            strDefaultView = "HR View";
                        }
                        //If logged in user is submitter or reports manager as well as HR as well as Approver
                        if ((strApprover.Trim().Length > 0 && boolIsApprover) && (strFormStatus != "Complete" && strFormStatus != "Denied" && strFormStatus != "Approved" && strFormStatus != "Pushed Back" && strFormStatus != "Submitted to Payroll"))
                        {
                            strDefaultView = "SMD View";
                        }
                        if (strDefaultView.Trim().Length > 0)
                        {
                            return strDefaultView;
                        }
                    }
                    //If logged in user is HR as well as Approver
                    if (boolIsHR && strManagerSubmitStatus == "1")
                    {
                        strDefaultView = "HR View";
                        if ((strApprover.Trim().Length > 0 && boolIsApprover) && (strFormStatus != "Complete" && strFormStatus != "Denied" && strFormStatus != "Approved" && strFormStatus != "Pushed Back" && strFormStatus != "Submitted to Payroll"))
                        {
                            strDefaultView = "SMD View";
                        }
                        return strDefaultView;
                    }
                    //If logged in user is only approver
                    string strHRSubmitStatus = myRoot.SelectSingleNode("/my:myFields/my:ValidationFields/my:HRSubmitStauts", NamespaceManager).Value;
                    if ((strHRSubmitStatus == "1" && boolIsApprover) && (strFormStatus != "Complete" && strFormStatus != "Denied" && strFormStatus != "Approved" && strFormStatus != "Pushed Back" && strFormStatus != "Submitted to Payroll"))
                    {
                        return "SMD View";
                    }
                    //If logged in user is only Payroll
                    string strPayroll = myRoot.SelectSingleNode("/my:myFields/my:PayrollSection/my:PayrollLanID", NamespaceManager).Value;
                    bool boolIsPayroll = IsLoggedInUserHRorPayroll(strPayroll, strLoggedInUser, ';', myRoot);
                    string strHRSubmitToPayroll = myRoot.SelectSingleNode("/my:myFields/my:ValidationFields/my:HRSubmitToPayroll", NamespaceManager).Value;
                    if (boolIsPayroll && strHRSubmitToPayroll == "1")
                    {
                       return "Payroll View";
                    }
                   

                    return "Blank View";
                }
                catch (Exception ex)
                {
                    _ExceptionMessage = (string)_ExceptionMessage + "Finding the Default View Method: " + ex.Message + "   ";
                    myRoot.SelectSingleNode("/my:myFields/my:ValidationFields/my:ExceptionMessage", NamespaceManager).SetValue((string)_ExceptionMessage);
                    return string.Empty;
                }

            }

    Regards,
    P V V S V Prasad
    Invesco
    MyBolg
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.