[Solved] Acces to User's Name or Shortcut in Basic

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
MartinaG
Posts: 2
Joined: Tue Jan 27, 2009 11:44 am

[Solved] Acces to User's Name or Shortcut in Basic

Post by MartinaG »

How can I access in a Basic Macro some of the user data stored in the openoffice installation under Extras/OpenOffice.org/userdata
(I guess that would be the English translation of this menu)?

The purpose is: I am writing a macro for a Base form and want to add the user's shortcut (and the date) to a record automatically, whenever a record is created or modified.

Thank you for your time!
m.g.


P.S: I am sorry, if this topic has already been discussed, but it is difficult to find a specific keyword that is not used in a myard of other contexts.
Last edited by MartinaG on Tue Jan 27, 2009 2:46 pm, edited 1 time in total.
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Acces to User's Name or Shortcut in Basic

Post by Villeroy »

You could read this from a form or report since forms and reports are Writer documents with properties.

Install http://extensions.services.openoffice.org/project/MRI
Open a document and call menu:Tools>Add-Ons>MRI to inspect the current document.
You find two services DocumentInfo and DocumentProperties. The first is documented as deprecated but still working.

This leads to the equivalent statements:

Code: Select all

print ThisComponent.DocumentProperties.Author
print ThisComponent.DocumentInfo.Author
http://api.openoffice.org/docs/common/r ... rties.html
http://api.openoffice.org/docs/common/r ... tInfo.html
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
MartinaG
Posts: 2
Joined: Tue Jan 27, 2009 11:44 am

Re: Acces to User's Name or Shortcut in Basic

Post by MartinaG »

Hello Villeroy,

Thank you for your quick reply. I am not sure we are talking about the same problem. I have a database on the fileserver of a local network, and four people are accessing it from their PCs. It would be nice if everybody who makes a modification on a recordset, could leave his name or shortcut in this recordset. (Otherwise we would insert it manually) Therefore the table has a coloumn named "last editor".

I guess what you are talking about is the author etc in a writer, calc,.. document. I guess the author of the Database will always be me.

I suppose everybody has his name in his OOo installation, I only do not know how to access it.

Or do you think I should make the user's OpenOffice to create a writer document and have a look who is the author and close that document again?

Thanks,
m.g
OOo 3.0.X on Ms Windows XP
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Acces to User's Name or Shortcut in Basic

Post by Villeroy »

Sorry, of course you are right. The database's forms and reports are created by you as author. And yes, creating a new office document, reading it's Author-property and close the document would be an easy way to get the info about the current user's name.
There are more complex methods to read the user profile using service com.sun.star.configuration.ConfigurationProvider

You are aware of the limitations of single-file, single-user databases on a file server? You know that Base is nothing but a frontend tool, even when it serves a single-file, single-user database?

Just a suggestion:
Install a multi-user database sever such as MySQL, Postgre, MS SQL, Oracle, HSQLDB or anything like that.
Distribute Base documents with forms to access the database server in a safe, secure and performant(*) way.

menu:Tools>SQL...
SCRIPT 'C:\Temp\Base.txt'
creates an SQL script, which should be able to reproduce the structure (tables, indices & relations) of your current single-file, single-user database on other SQL-capable servers.

(*)
Safe: The way how Base wraps a HSQL database into a single file increases the chance to lose data due to software failure. A normal database server is by safer, even in case of hardware failure. As always, there is no safety without a consequent backup-strategy.
Secure: A normal database knows about privileges for database users and groups of users, so everybody needs to log-in before he is allowed for editing, viewing or manipulating the database. Base can forward log-ins to database servers.
Performant: The way how Base wraps a HSQL database into a single file will slow down the whole thing while it keeps on growing over time.
When you "open" the database document, the whole database is extracted into a temporary directory before OOo's built-in HSQL-server can connect to the extracted thing. You work with a database in a temporary directory served by an HSQLDB-server. Your database will be compressed into the database document when you "close" it.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31345
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Acces to User's Name or Shortcut in Basic

Post by Villeroy »

myself wrote:There are more complex methods to read the user profile using service com.sun.star.configuration.ConfigurationProvider
Found it:

Code: Select all

Sub test_UserProfileData() As String
REM look at file <<OOo-Profile/3/user/registry/data>> /org/openoffice/UserProfile.xcu, XML-node "Data":
Const sNodePath$ = "/org.openoffice.UserProfile/Data"

oNode = getOOoSetupNode(sNodePath$)
snval = oNode.getByName("sn")
gnval = oNode.getByName("givenname")
ival = oNode.getByName("initials")
print gnval,snval,ival
End Sub

Function getOOoSetupNode(sNodePath$)
Dim aConfigProvider, oNode, args(0) As new com.sun.star.beans.PropertyValue
	aConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
	args(0).Name = "nodepath"
	args(0).Value = sNodePath
	getOOoSetupNode = aConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", args())
End Function
How can I access in a Basic Macro some of the user data stored in the openoffice installation under Extras/OpenOffice.org/userdata
(I guess that would be the English translation of this menu)?
German menu Extras>Optionen... is Tools>Options...
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply