This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Auto transition vbscript time stamp

Hello can someone help me with my script.  I don't know how to know time differential and date differential using time stamp (created) property.

here is my WIP vbscript, i want to allow transition if the time differential of time stamp is 24 hours. 

Option explicit
Dim classID, szDate, DateDsz
classID = PropertyValues.SearchForProperty(100).TypedValue.GetValueAsLookup().Item
szDate = CDate(PropertyValues.SearchForProperty( 20 ).TypedValue.DisplayValue)
DateDsz = DateDiff("h",Date,szDate)
If classID = 41 or classID = 42 or classID = 202 Then
If  DateDsz = 24 or  Then
AllowStateTransition = True
End if
End if

Thank you.

Parents
  • Looks like you are fairly close.
    I would use this line to check the result of your DateDsz calculation (insert it temporarily just after the calculation)

    err.raise MFScriptCancel, DateDsz

    From the looks of it you may get negative results. If so you can switch the order of Date,szDate, or you can adjust the next lines to work with the negative result.

    You should also have a look on this line:
    If  DateDsz = 24 or  Then

    You need to remove OR, and you should use DateDsz >= 24 to allow for situations where more than 24 hours may have passed.

  • I followed your suggestion for the error.  i adjusted the Order to DateDsz = DateDiff("h",Date,szDate)

    and got an error of -13 and if put the same i got error 13.

    I edited my script like this now to test if with minutes. But it's not transitioning after 2 minutes or so.

    Option explicit
    Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    Dim oObjId : Set oObjId = CreateObject("MFilesAPI.ObjID")
    Dim classID, szTime, TimeDsz
    classID = PropertyValues.SearchForProperty(100).TypedValue.GetValueAsLookup().Item
    szTime = CDate(PropertyValues.SearchForProperty(20).TypedValue.DisplayValue)
    TimeDsz = DateDiff("n",Date,szTime)
    If classID = 41 or classID = 42 or classID = 202 Then
    If TimeDsz = 2 Then
    AllowStateTransition = True
    End if
    End if

  • The "error" should be the result of your calculation.
    If that looks correct, your calculation is in order. Then you just have to wait until 24 hours have passed.
    Changing to Minutes will not make much of a difference anyway. The server is only checking once per hour (default setting), so the transition will happen some time within an hour after your "IF" becomes true.

  • The error means the result of the calculation? I've tested it if the object was created at 2pm the erorr says 14. so it means 1400h? I also change the sequence from Date,szDate to szDate the result was -14.

    So the non negative result means the correct one?

Reply Children