Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: RubenK on December 09, 2016, 10:08:47 pm
-
I have a problem with implementing just a simple user approval system in EA.
So what we want is; usergroup A can change the status of a package in the model from proposed to approved.
Other usergroups can not do this change..
My idea was that workflowscripts is the best way to solve this, and I have tried to write a script for this.
public function AllowStatusUpdate( OldValue, NewValue )
dim currentUser, currentItem
set currentUser = WorkflowUser
set currentItem = WorkflowContext
If OldValue = "proposed" and WorkflowUser.IsMemberOf("GroupA") and NewValue = "approved" and WorkflowContext.Metatype = "Package"
Then
AllowStatusUpdate = true
else
AllowStatusUpdate = false
end if
end function
However, this is not doing anything. Does anybody have experience with this? And what am I doing wrong?
-
No idea. Just at a guess, instead of
If OldValue = "proposed" and WorkflowUser.IsMemberOf("GroupA") and NewValue = "approved" and WorkflowContext.Metatype = "Package"
Then
AllowStatusUpdate = true
else
AllowStatusUpdate = false
end if
try
return ( OldValue = "proposed" and WorkflowUser.IsMemberOf("GroupA") and NewValue = "approved" and WorkflowContext.Metatype = "Package" )
(does VB use = or == for comparison?)
q.
-
VBScript uses '=' for comparison and for assignment of primitive values.
It doesn't have a return keyword (or doesn't use it in that way)
My guess is that putting the 'Then' on the next line is the issue. Newlines are significant (Use _ as the last character on the line to escape the newline) and all the examples I've seen have 'Then' on the same line as the 'if'.
public function AllowStatusUpdate( OldValue, NewValue )
If OldValue = "proposed" and WorkflowUser.IsMemberOf("GroupA") and NewValue = "approved" and WorkflowContext.Metatype = "Package" Then
AllowStatusUpdate = true
else
AllowStatusUpdate = false
end if
end function
or
public function AllowStatusUpdate( OldValue, NewValue )
AllowStatusUpdate = (OldValue = "proposed" and WorkflowUser.IsMemberOf("GroupA") and NewValue = "approved" and WorkflowContext.Metatype = "Package")
end function
However, given that that will mean that no-one can change any status except packages from proposed to approved:
public function AllowStatusUpdate( OldValue, NewValue )
If OldValue = "proposed" and NewValue = "approved" and WorkflowContext.Metatype = "Package" Then
AllowStatusUpdate = WorkflowUser.IsMemberOf("GroupA")
else
AllowStatusUpdate = true
end if
end function
Also, check that "proposed" and "approved" are used all lower case. That's a case-sensitive comparison if I remember correctly.
-
Hi Simon,
Thanks for the help and explanation.
I changed the scipt but i m still struggeling on this. My script runs in a workflow group, and after switching users it should activate.
However a user from "GroupB" can still change the status of a package from proposed to approved.
Script is now:
option explicit
!INC Local Scripts.EAConstants-VBScript
dim ERROR_OUTPUT
ERROR_OUTPUT = "MessageBox"
public function AllowStatusUpdate( OldValue, NewValue )
dim currentUser, currentItem
set currentUser = WorkflowUser
set currentItem = WorkflowContext
If OldValue = "proposed" and NewValue = "approved" and WorkflowContext.Metatype = "Package" Then
AllowStatusUpdate = WorkflowUser.IsMemberOf("GroupA")
else
AllowStatusUpdate = true
end if
end function
i think that WorkflowContext.Metatype = "Package" is not doing what i want, but im not sure.
If anyone has any idea what i am doing wrong let me know!
-
Generally you should try inserting debug print statements that write to the system output.
q.
-
Yay its working!! :D Thanks for the help!