[Solved] Accessing File > Properties > User Defined fields

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

[Solved] Accessing File > Properties > User Defined fields

Post by Lazy-legs »

Hello,

It's rather easy to retrieve document properties stored in File -> Properties -> General. For example, using the following code, you can retrieve the current document's title:

Code: Select all

ThisDoc=ThisComponent
DocName=ThisDoc.DocumentInfo.Title
I wonder whether it's possible to access the use-defined fields under the User Defined tab in a similar manner? For example, I'd like to rename the Info 1 field to Status, so I can retrieve the document's status via a macro. Is this doable?

Thank you!

Kind regards,
Dmitri
Last edited by Hagar Delest on Tue Jun 10, 2008 2:02 pm, edited 3 times in total.
Reason: tagged the thread as Solved.
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Accessing Use Defined fields

Post by JohnV »

The first macro will change the Info 1 field found at File > Properties > User Defined tab to Status but why bother. The second macro will read the content of that field no matter what its name is.

Code: Select all

Sub Main
ThisDoc=ThisComponent
ThisDoc.DocumentInfo.setUserFieldName(0,"Status")
End Sub

Sub GetInfo1
MsgBox ThisComponent.DocumentInfo.getUserFieldValue(0)
End Sub
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: Accessing Use Defined fields

Post by Lazy-legs »

Thank you very much, JohnV!

Kind regards,
Dmitri
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: [Solved] Accessing Use Defined fields

Post by JohnV »

I would suggest that you or a moderator change the Subject of your original post to:
[Solved] Accessing File > Properties > User Defined fields
User avatar
Hagar Delest
Moderator
Posts: 32594
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: [Solved] Accessing File > Properties > User Defined fields

Post by Hagar Delest »

Done.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Lazy-legs
Posts: 71
Joined: Mon Oct 08, 2007 1:33 am
Location: Århus-Berlin

Re: [Solved] Accessing File > Properties > User Defined fields

Post by Lazy-legs »

Sorry, I should have done this myself. I'll try to remember this next time.

Kind regards,
Dmitri
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: [Solved] Accessing File > Properties > User Defined fields

Post by JohnV »

Thinking about the viewing macro today I realized we can either view or edit it all in one macro. So let's kill two birds with one stone.

Code: Select all

Sub ViewOrEditInfo_1
Dim s,a,n : s = ThisComponent.DocumentInfo.getUserFieldValue(0)
a = "You can edit the current text in the Info 1 field below." & Chr(13)
a = a & Chr(13) & "'OK' accepts edited text, 'Cancel' leaves it alone."
n = InputBox(a,,s)
If n = "" then End
ThisComponent.DocumentInfo.setUserFieldValue(0,n)
End Sub
Post Reply