How can I pass a Session["UserId"] to a Infopath Form

  • Thread starter DotNet Guerrilla
  • Start date
D

DotNet Guerrilla

Hi,
I am deploying a InfoPath form using sandbox, and I have to pass the user id
session to the InfoPath form to query a web service. How can pass any
parameter to a InfoPath form. Do you think if I use the Custom Task Pane and
access the InfoPath Object Model from the page will work? Please advice!

Thanks
 
F

Franck Dauché

Hi,

You can't pass parameters to InfoPath directly. A popular workaround is to
store your UserId as a node in your schema. Now, you can set the value of
that node in your xml document before you open it with InfoPath. Next, you
can read that node value by code, when the form loads by example, and use it
to call your Web Service by code.

Hope that it helps.

Franck Dauché
 
D

DotNet Guerrilla

The userid will not be static, that will change depend of the user who signed
in, because I have to return different Dataset from the Web Service using the
userid. What about using the custom task pane?

Thank you for your help!
Adolfo
 
F

Franck Dauché

Hi,

I understand that your userid is not static, that's why I suggested that it
could be set outside InfoPath (while cashing the form to your user's machine
for example).
If you don't like (or can't do this), another way is to get it by code On
form Load:

var userName; //user logon name
function XDocument::OnLoad(eventObj)
{
var objNetwork = new ActiveXObject("WScript.Network");
//Get logged-on user name
userName = objNetwork.UserName;
wshNetwork = null;
}


Now, to answer your question, yes, you can use the Taskpane. But, if you go
that route and that your user has to enter a user id manually in the form,
why don't you do a login screen when you open your form? It might be cleaner
and more intuitive to the user.

Does it make sense?

Franck Dauché
 
J

Joe Colletti

I am deploying a InfoPath form using sandbox, and I have to pass the user id
session to the InfoPath form to query a web service. How can pass any
parameter to a InfoPath form. Do you think if I use the Custom Task Pane and
access the InfoPath Object Model from the page will work? Please advice!

Since you are using a web service, you can do it directly in the service as
long as you are using the service as your default receive service. I do the
same thing here.
Just make sure to have your WHERE clause of your SQL Data Adapters SELECT
statement include the parameter, like "WHERE UserName = @UserName". Then you
just add the Parameter like shown below.
<WebMethod()> _
Public Function ReceiveUpdateMyApplication() As DataSet
Dim Usr As String =
System.Web.HttpContext.Current().User.Identity().Name
If Usr.IndexOf("\") > 0 Then
Usr = Usr.Split("\").GetValue(1)
End If
SDA_UpdateMyApplication.SelectCommand.Parameters.Item(0).Value() = Usr
SDA_UpdateMyApplication.Fill(DS_UpdateMyApplication)
Return DS_UpdateMyApplication
End Function

Good Luck,
Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top