Book a Demo

Author Topic: Workflow script - Basic user approval  (Read 5301 times)

RubenK

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Workflow script - Basic user approval
« 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?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Workflow script - Basic user approval
« Reply #1 on: December 10, 2016, 01:07:56 am »
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.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8090
  • Karma: +118/-20
    • View Profile
Re: Workflow script - Basic user approval
« Reply #2 on: December 12, 2016, 08:54:43 am »
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.
« Last Edit: December 12, 2016, 08:57:40 am by Simon M »

RubenK

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Workflow script - Basic user approval
« Reply #3 on: December 12, 2016, 09:04:31 pm »
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!
« Last Edit: December 12, 2016, 09:28:44 pm by RubenK »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Workflow script - Basic user approval
« Reply #4 on: December 12, 2016, 10:26:28 pm »
Generally you should try inserting debug print statements that write to the system output.

q.

RubenK

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: Workflow script - Basic user approval
« Reply #5 on: December 12, 2016, 10:34:39 pm »
Yay its working!! :D Thanks for the help!