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;
}
}