Hilary,
That was what I needed! :) My code is below in case anyone else tries something similar. Basically I use the DBXL AD Service (as a Data Control in my form) to find the department of the current user, then I query my DB Stored Procedure to get a New Form ID. I "only" do this if the Form is "new".
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
if (this.New)
{
string currentUser = System.Environment.UserName.ToString();
string department = GetDepartmentOfCurrentUser(currentUser);
string formNumber = GetFormNumberByUserAndDepartment(department, currentUser);
XPathNavigator xn = this.MainDataSource.CreateNavigator();
XPathNavigator xnFormNumber = xn.SelectSingleNode("/my:myFields/my:Form_Number", this.NamespaceManager);
xnFormNumber.SetValue(formNumber);
}
}
private string GetFormNumberByUserAndDepartment(string department, string currentUser)
{
//Set the Command for the Query Adapter of the Data Source. Incorporate the
//parameter values that you want to use.
string query = "DECLARE @return_value int, @FormNumber varchar(50) " +
"EXECUTE [dbo].[FetchNextFormNumber] @UserName = N'" + currentUser + "', @Department = N'" + department + "', @FormNumber = @FormNumber OUTPUT SELECT @FormNumber AS formNumber";
AdoQueryConnection myAdoQueryConnection =
(AdoQueryConnection)(this.DataConnections["FormNumberLookup"]);
string oldCmd = myAdoQueryConnection.Command;
myAdoQueryConnection.Command = query;
myAdoQueryConnection.Execute();
myAdoQueryConnection.Command = oldCmd;
XPathNavigator myNavigator =
this.DataSources["FormNumberLookup"].CreateNavigator().SelectSingleNode("//dfs:myFields/dfs:dataFields/d:row/@formNumber", this.NamespaceManager);
return myNavigator.Value;
}
private string GetDepartmentOfCurrentUser(string currentUser)
{
//Set the Command for the Query Adapter of the Data Source. Incorporate the
//parameter values that you want to use.
WebServiceConnection myWSConnection =
(WebServiceConnection)(this.DataConnections["GetMyInfo"]);
myWSConnection.Execute();
XPathNavigator myNavigator =
this.DataSources["GetMyInfo"].CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:GetMyInfoResponse/tns:GetMyInfoResult/tns:ADProp[tns:Key[text()='department']]/tns:Value", this.NamespaceManager);
return myNavigator.Value;
}
}