Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

How to get the name of a web user

This is the  code i have written for an agent:
Dim Session As New NotesSession
     Dim db As NotesDatabase
     Dim curdoc As NotesDocument    
     Dim remcreator As NotesItem
     
     Set db=Session.CurrentDatabase
     Set curdoc=Session.DocumentContext
     Set remcreator=curdoc.GetFirstItem("FNRemCreators")
     Set usr=New NotesName(Session.Username)
     remcreator.AppendToTextList(curdoc.remote_user(0))
     Msgbox curdoc.Remote_User(0)
     curdoc.Save True,False

The purpose of this agent is to trap the name of the user who is calling the agent and append the name to the FNremCretors field.
On the Notes client I can do this using Session.UserName but on the browser it returns me the server name.Although I login to the browser using admin but it is unable to trap the value using this code.Any clues???
0
sampa
Asked:
sampa
  • 3
  • 3
  • 2
1 Solution
 
Jean Marie GeeraertsCommented:
First of all you need to set the agent to run as web user, otherwise the name of the server will be returned.
To do this open the agent properties from the agent list, then on the third tab check the checkmark for "Run Agent as Web user".

To get the name of the currently logged on user, use the EffectiveUserName property of NotesSession.

So in your code this would be:
Set usr=New NotesName(Session.EffectiveUserName)

Regards,
JM
0
 
zvonkoCommented:
Hello JM, hello sampa,

Alternatively to setting this option for the agent as upper proposed is there a more simple way getting current web user name: create an additional field on your form and placing a value @Formula to get current logon name of the web user. Do not hide the field with Notes hide-when methods; use http option: “type=hidden” or enable form option: GenerateHtmlForAllFields
One of the suitable value formulas could be: @Name([CN];@UserName)

This method is especially useful if you do not like to loose agent privileges granted from agent signer (saving designer) by using RunAsWebUser option.

Regards,
zvonko

0
 
sampaAuthor Commented:
Jerrith,thanks for the help but effectiveUserName returns the person who last saved the script but i do not want that I want the person who has currently logged in.I think that way zvonko ur suggestion satisfies the requirement.
Thanks
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Jean Marie GeeraertsCommented:
EffectiveUsername will return the current username if the agent is run as web user.
You have not set the option as I specified, otherwise it would work, without the use of an extra field on the form.
0
 
sampaAuthor Commented:
I checked out with everything that u had given but although i had logged in as user1 it was showing me admin and i checked the doc properties it showed modified by admin.
0
 
zvonkoCommented:
Thank you for the points :-)

But my buddy JM is right: you surely made a mistake testing his proposal.

Here is my code testing his proposal and getting the described result: effective web user name

Sub Initialize
     Dim Session As New NotesSession
     Dim usr As NotesName
     Set usr=New NotesName(Session.EffectiveUserName)
     Print "Starting...<br>"
     Print "User: " & usr.Common
End Sub

Cheers,
zvonko

PS: you need two print lines on web! Otherwise is a single print line interpreted as redirection URL by Domino web engine.

0
 
Jean Marie GeeraertsCommented:
It's not the document properties, but the agent properties from the agent list that you need to check.
There is on the design tab of the agent an option you need to check to run an agent as web user.
You need to make sure that the user has sufficient rights to run the agent and perform actions that are performed in the agent for this option to be effective.
I mostly use this option for WebQueryOpen agents where the document is modified and saved when the document is opened from web. (Otherwise you get a save or replication conflict when saving the document afterwards)
0
 
sampaAuthor Commented:
See actually there is an action called Create Remark which is there on a response doc which has already been created.Once I click on the action I should be able to create a resp to resp doc.Now my purpose is to check whether this user has already created a resp to resp for the current resp doc.If it is so then stop creation of further resp to resp docs.

Jerrith I have checked the same from agent properties.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now