MS Office Forum / General MS InfoPath Questions / August 2005
Infopath and AD
|
|
Thread rating:  |
Ronald R - 02 Aug 2005 20:03 GMT Is there anyway for Infopath to pull usernames and other info from active directory in a 2003 environment ?
Scott L. Heim [MSFT] - 02 Aug 2005 22:44 GMT Hi Ronald,
Yes - the following is sample VBScript:
Function GetADInfo Dim objADSystemInfo Dim objUser Dim objManager Dim strLogin Dim strMail Dim strAlias Dim objGroup Dim strGroups Set objADSystemInfo = CreateObject("ADSystemInfo") Set objUser = GetObject("LDAP://" + objADSystemInfo.UserName) Set objManager = GetObject("LDAP://" + objUser.Get("manager")) 'Get all the groups the user is enrolled in 'For Each objGroup In objUser.Groups ' strGroups = strGroups & vbcrlf & objGroup.name 'Next strLogin = objUser.Get("cn") strMail = objUser.Get("mail") strAlias = left(strMail, instr(1, strMail, "@")-1) 'XDocument.UI.Alert "User: " & strLogin & vbcrlf & "Alias: " & strAlias & vbcrlf & "Manager: " & objManager.Get("name") & _ 'vbcrlf & "E-mail: " & strMail GetADInfo = strAlias End Function
As an example, I have a field on my form (field1) and on the Load event of the form, I have the following:
Dim objUser Set objUser = XDocument.DOM.selectSingleNode("//my:myFields/my:field1") If objUser.Text = "" Then objUser.Text = GetADInfo End If
So if field1 is blank, it calls the AD code and populates the text box with the user's name.
I hope this helps!
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Blackduke - 04 Aug 2005 02:33 GMT sorry can you clarrify this for me please, there are two pieces of code there i understand that the second piece you use as a action but where does the first piece of code go
sorry if this is a silly question
thanks
>Dim objUser > Set objUser = XDocument.DOM.selectSingleNode("//my:myFields/my:field1") > > If objUser.Text = "" Then > objUser.Text = GetADInfo > End If Scott L. Heim [MSFT] - 04 Aug 2005 14:37 GMT Hi,
My apologies as I did not intend for this to be confusing. The function (GetADInfo) is simply pasted into the script editor behind your InfoPath solution: - From the Tools menu choose Programming and then select Microsoft Script Editor - Scroll to the bottom of all code and paste the function
- The second part of what I provided was merely to describe how that function could be used. One way I have used this was to place this code:
Dim objUser Set objUser = XDocument.DOM.selectSingleNode("//my:myFields/my:field1") If objUser.Text = "" Then objUser.Text = GetADInfo End If
In the "Load" event of the form (Tools->Programming->On Load Event.) Keep in mind, this is just a sample and assumes there is a field on the form named: field1 that resides in the myFields layer. So this sample code first checks to see if "field1" is empty and if so calls the GetADInfo function to populate that field.
There is one additional item I forgot to mention: this code will require your form to be fully trusted. If you would like to get more information on fully trusted forms, take a look at the following:
Deploy a Fully Trusted Form to a SharePoint Form Library http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkDeployURNFormToSharePoint_HV01086376.asp
Understanding Fully Trusted Forms http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkUnderstandingFullyTrustedForms.asp
Using the Form Registration Tool http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkUsingTheFormRegistrationTool.asp
I hope this helps!
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Blackduke - 05 Aug 2005 10:45 GMT You are awsome thanks
>Hi, > [quoted text clipped - 44 lines] > >This posting is provided "AS IS" with no warranties, and confers no rights. Linda - 09 Aug 2005 09:06 GMT Hi Scott,
I have used code very similar to yours to extract a user's details from AD. When I first tested it in Infopath Preview mode, all worked fine. I then put the form into Sharepoint and invoked it from there. I got the error message "ActiveX component can't create object: 'ADSystemInfo'". Now I'm getting this message even in Preview mode.
I've tried rebooting the server. Any ideas?
Ta,
 Signature Linda
> Hi Ronald, > [quoted text clipped - 48 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 09 Aug 2005 14:06 GMT Hi Linda,
In one of my prior posts in this thread (and I forgot to mention it in my initial response...my apologies) was that in order for this code to run, your form will need to be "fully trusted." You can make your form fully trusted by using either digital certificates or building an install package for your form using the "RegForm" tool from the InfoPath SDK.
Here are some links that you may find of interest:
How to Deploy a Fully Trusted Form to a SharePoint Form Library http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkDeployURNFormToSharePoint_HV01086376.asp
InfoPath SDK http://www.microsoft.com/downloads/details.aspx?FamilyId=351F0616-93AA-4FE8- 9238-D702F1BFBAB4&displaylang=en
InfoPath Technical FAQ http://www.microsoft.com/technet/prodtechnol/office/office2003/plan/inpthfaq .mspx#ECBAA
InfoPath Toolkit for VS.NET http://www.microsoft.com/downloads/details.aspx?FamilyID=7e9ebc57-e115-4cac- 9986-a712e22879bb&DisplayLang=en
Understanding Fully Trusted Forms http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkUnderstandingFullyTrustedForms.asp
Using the Form Registration Tool http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkUsingTheFormRegistrationTool.asp
I hope this helps! :-)
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Linda - 12 Aug 2005 09:19 GMT Scott, I followed the instructions and used RegForm to make the form fully trusted then used the generated .js file to install the form on a Client PC. When I invoked the form I got the message: "The form template is trying to access files and settings on your computer. InfoPath cannot grant access to these files and settings because the form template is URL-based. Only URN-based templates, which have been locally installed on your computer, can be granted access."
I then found some instructions about changing the .xsf and .xml files to make the form urn based. Having made the changes, I republished the form back to Sharepoint and used cabarc to build a CAB file. I didn't quite understand what I needed to do by the next instruction, which was to create a custom installation program to install the form again, so I renamed the cab file to match the original .xsn name and rerun the .js file (after using formname /uninstall first) on the Client PC. It didn't make any difference and I am still getting the message that the form template is URL based.
This is the first time I've tried to use Infopath and do anything similar so please forgive me if I am being obviously naive. Thanks for your help so far.
 Signature Linda
> Hi Linda, > [quoted text clipped - 36 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 12 Aug 2005 15:36 GMT Hi Linda,
I would like to get a couple of clarifications:
- When you ran the RegForm tool to create the "js" file, it should have created a ".BAK" file of your template - is this the case? - When you double-click the "new" XSN that gets created, is this where you are seeing the message?
The key thing I want to be sure of is that you are using the "new" XSN file after running the JScript file.
Best Regards,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Linda - 15 Aug 2005 03:52 GMT Hello again, Yes, a .BAK file is created. Not sure what you mean by a "new" XSN file - only one exists and yes, it is updated. I don't get the "URL based" message when I double-click on the xsn file, it occurs after I republish it to Sharepoint and invoke it from the Sharepoint site. Really appreciate your help with this...
 Signature Linda
> Hi Linda, > [quoted text clipped - 14 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 15 Aug 2005 13:51 GMT Hi Linda,
Thank you for the clarifications - they were helpful!
When deploying a trusted solution to a Sharepoint library there are some steps you will *not* do and some additional steps you *must* do in order for this to work.
For instance, you will not actually "publish" your newly trusted form to Sharepoint - you will need to manually create the library and then copy a specific file to the "Forms" folder in that library.
The complete steps you will need to follow are in this link:
Deploy a Fully Trusted Form to a SharePoint Form Library http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkDeployURNFormToSharePoint_HV01086376.asp
Specifically, you will want to pay close attention to the steps 2 and 3 in this section: Deploying a Fully Trusted, Registered Form to a Form Library
Let me know how it turns out! :-)
Best Regards,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Linda - 18 Aug 2005 12:01 GMT Finally. After a lot of problems with permissions and security, I have got it to work...and have repeated the process to document the steps for future reference. One thing I'm not sure of now though is what to do if I use SP1 on Infopath. It generates a URN based form instead of a URL based one but I can't make it fully trusted in the same way. Does using SP1 make deployment any easier/less cumbersome? A pointer to some documentation on this would be great.
Thanks again for your help.
 Signature Linda
> Hi Linda, > [quoted text clipped - 25 lines] > > This posting is provided "AS IS" with no warranties, and confers no rights Scott L. Heim [MSFT] - 18 Aug 2005 14:21 GMT Hi Linda,
That's great to hear!
With regard to SP1 if you have not yet installed this I would highly suggest doing so...much of the standard things one would do in developing with InfoPath is significantly easier!
To address your question of a fully trusted form with SP1 - you now have a couple of options: you can still use the RegForm process but you can also "sign" the form with a digital certificate. Obviously this would require that you (your company) either have a certificate server setup or you get a "code signing" certificate from a Root Certification Authority such as VeriSign (there are numerous others as well.)
With a certificate you would not need to use the RegForm process so when users first launch the form, they would get the standard "warning" message but they would have the option to "trust content from this publisher" (being you) and once they enable that option you are trusted!
Here is some additional information that may help:
Deploying Signed Form Templates [InfoPath 2003 SDK Documentation] http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ ipsdkSignedFormTemplate_HV01120501.asp
Let me know if you have any additional questions!
Take care,
Scott L. Heim Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights
Radovan - 08 Aug 2005 13:58 GMT var oNet = new ActiveXObject("Wscript.Network"); sUserID = oNet.UserName; XDocument.UI.Alert(sUserID);
That is all Folks :))
> Is there anyway for Infopath to pull usernames and other info from active > directory in a 2003 environment ?
|
|
|