Book a Demo

Author Topic: Problem with ReleaseUserLock or ReleaseUserLockRecursive in EA repository  (Read 6836 times)

[email protected]

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
I was looking for solution for release locks on choosed package in project browser.

I read that it was not available in EnterpriseArchitect a long time ago, but it is currently included in the documentation here: https://www.sparxsystems.fr/resources/user-guides/automation/enterprise-architect-object-model.pdf therefore I would expect that it is already operational. Could someone help me what am I doing wrong?

Code: [Select]
!INC Local Scripts.EAConstants-VBScript

sub main
    Dim Repository As EA.Repository
    Set Repository = GetObject(, "EA.App").Repository
    'actual package
    Dim SelectedPackage As EA.Package
    Set SelectedPackage = Repository.GetTreeSelectedPackage
   
    if Not SelectedPackage Is Nothing Then
           
            Dim status
            Set status = SelectedPackage.ReleaseUserLock(True, True, True)
           
            if status = 1 Then
                Session.Output("Unlocked")
            else
                Session.Output("failed")
            end if
           
    Else
        Session.Output("Není vybraný")
       
    End if
   
end sub

main

I find it interesting that this code ends up with the error "requested object", yet the lock is removed from the package. I couldn't even achieve this result in JS...

I tried using both VB and JS script. Next, I managed to check t_secuser where I have UserSecurity enabled in t_secpolicies and at the same time database administrator permissions

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
As I told you on SO this function returns a bool and not an objet (which you did declare wrongly btw.). Maybe you should practice VB a bit?

q.

[email protected]

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Ok than, let make it more simple. This code has still problem with procedure ReleaseUserLockRecursive "Problem with Sub procedure"...

Code: [Select]
option explicit

!INC Local Scripts.EAConstants-VBScript

sub main
    Dim Repository As EA.Repository
    Set Repository = GetObject(, "EA.App").Repository
    'actual package
    Dim SelectedPackage As EA.Package
    Set SelectedPackage = Repository.GetTreeSelectedPackage
    Dim status
    if Not SelectedPackage Is Nothing Then
    SelectedPackage.ReleaseUserLockRecursive(True, True, True)
            Session.Output("Unlocked")                 
    Else
        Session.Output("Not chosen")
       
    End if
   
end sub

main

Any recommendation from Sparx?

 

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Well, I used the suggested syntax in the editor:

Code: [Select]
Dim status
status = SelectedPackage.ReleaseUserLock()

which did run. Of course it failed since I have not set locking. Why did you supply these parameters. Did you RTFM? It doesn't show any. And the intellisense neither. Once in a while Sparx is not to blame...

Now, how do I get the dirt off my fingers???

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Code: [Select]
    SelectedPackage.ReleaseUserLockRecursive(True, True, True)
This is again a syntax error. You are not allowed to use parentheses when calling a function and not using it's return type.
Correct alternatives are

Code: [Select]
    SelectedPackage.ReleaseUserLockRecursive True, True, Trueor
Code: [Select]
    status = SelectedPackage.ReleaseUserLockRecursive(True, True, True)
Geert

[email protected]

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Hi Geert, many thanks for your comment. Now I have tested it and it has started worked for me.
Code: [Select]
if Not SelectedPackage Is Nothing Then
    SelectedPackage.ReleaseUserLockRecursive True, True, True
        Session.Output("Unlocked")                 
    Else
        Session.Output("Not chosen")
       
    End if

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Interesting. The linked documentation says the operation does not take any parameter at all. And (IIRC) when testing the intellisense did also suggest no parameter.

q.

P.S. Only ApplyUserLockRecursive takes three bools.
« Last Edit: August 29, 2023, 02:43:31 am by qwerty »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
It's only ReleaseUserLockRecursive that has the parameters

From the manual:

Quote
ReleaseUserLock ()

Boolean

Notes: Releases user locks and group locks from the Package object, and all of the Packages, diagrams and elements contained within that Package. User Security applies to the use of this function; if the user does not have permission to apply or release locks on elements, diagrams and Packages, the operation will fail.

Returns True if the operation is successful; returns False if the operation is unsuccessful. Use GetLastError() to retrieve error information.

ReleaseUserLockRecursive (boolean IncludeElements,
boolean IncludeDiagrams,
boolean IncludeSubPackages)

Boolean

Notes: Releases user locks from the Package object, and all of the Packages, diagrams and elements contained within that Package. User Security applies to the use of this function; if the user does not have permission to apply or release locks on elements, diagrams and Packages, the operation will fail.

Returns True if the operation is successful; returns False if the operation is unsuccessful. Use GetLastError() to retrieve error information.

Parameters

IncludeElements: Boolean - Recursively release user locks from child elements

IncludeDiagrams: Boolean - Recursively release user locks from child diagrams

IncludeSubPackages: Boolean - Recursively release user locks from child Packages

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Hmm. The above linked docu differs...

q.

P.S. It's a bit outdated? (From 2016) and does not mention the EA version it's made for. At least not obviously.
P.P.S. And it refers to the French Sparx site...
« Last Edit: August 29, 2023, 02:47:59 am by qwerty »