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

Problem with VBScript

Hello,

 the attached script should calculate the property value in a certain class within a certain workflow and state. The script works inside the  loop, but the "if" condition is wrong. In what way could it be remade?

Dim dtToday
Dim documentClass
Dim iWorkflow
Dim iWorkflowState


documentClass = PropertyValues.SearchForProperty(100).TypedValue.DisplayValue
iWorkflow = PropertyValues.SearchForProperty(38).TypedValue.DisplayValue
iWorkflowState = PropertyValues.SearchForProperty(39).TypedValue.DisplayValue


if documentClass = "Mileage Status" or documentClass = "Employee Car"  and iWorkflowState = "2.1 Mileage Status" and iWorkflow = "Employee Car Process" then

dtToday = Now
Dim dtLastDay
dtLastDay = DateSerial(Year(dtToday), Month(dtToday) + 1, 0)


if dtToday = dtLastDay then
dtLastDay = DateSerial(Year(dtToday), Month(dtToday) + 2, 0)
end if

Output = dtLastDay

else
' '

end if

  • I'm not really sure what you're asking.  I don't see a loop.  Do you get an error?  Is the logic for the and/or conditions incorrect?  You don't have a fallback value for "Output", but I guess you don't want a value in other situations...

    I would personally change the code in a few ways, but they probably won't help with your specific issue:

    • Add Option Explicit at the top of the script, to force variable declaration.
    • I would use the actual lookup IDs in the code rather than checking the class / state names, as these can change too easily.
  • When combining AND and OR conditions in your if statement in line 12 you should use paranthese () to indicate in which order they have to be considered. It should probably be something like:

    if (documentClass = "Mileage Status" or documentClass = "Employee Car")  and iWorkflowState = "2.1 Mileage Status" and iWorkflow = "Employee Car Process" then

  • Hello,

    I try on this way and I got the error: The operation failed. Not found. Did you maybe have some other ideas?

  • What's the full error stack? 

  • Which line creates the new error?

    I suspect the error comes from a different line than the IF statement, possible from line 26. Not  quite sure what you are trying to achieve there. It probably should be
       Output = ''

  • This is error when i try run Recalculate. 

    When I go check in Event Viewer this is full error details:

    The job "Recalculate" finished running.

    Status: Failed. Error: Not found.

    RPCScheduledJobsHelper.cpp, 3217, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RPCScheduledJobsHelper.cpp, 2709, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1113, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 899, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1881, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1601, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1435, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1668, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1379, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 275, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 340, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 340, Not found. (0x8004000B)
    VaultScriptSessionTemplates.cpp, 523, Not found. (0x8004000B)
    CoActiveScriptSite.cpp, 895, Not found. (0x8004000B)
    CoActiveScriptSite.cpp, 737, Not found. (0x8004000B)
    Next Mileage Status Date, PropertyDefCalculatedValue, 10, Not found. (0x8004000B)
    MNullPropagatingDispatchImpl.h, 126, Not found. (0x8004000B)
    MNullPropagatingDispatchImpl.h, 173, Not found. (0x8004000B)
    CoPropertyValues.cpp, 347, Not found. (0x8004000B)
    (M-Files 22.6.11534.5 2023-02-06T07:47:13.995Z)

    Job type: Recalculate

  • When i start Recalulate operation i got this error:

    And this is event from event viewer:

    Status: Failed. Error: Not found.

    RPCScheduledJobsHelper.cpp, 3217, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RPCScheduledJobsHelper.cpp, 2709, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1113, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 899, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1881, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1601, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1435, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1668, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    RecalculateProperties.cpp, 1379, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 275, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 340, Script execution failed. ((Next Mileage Status Date, PropertyDefCalculatedValue: 10-999-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 340, Not found. (0x8004000B)
    VaultScriptSessionTemplates.cpp, 523, Not found. (0x8004000B)
    CoActiveScriptSite.cpp, 895, Not found. (0x8004000B)
    CoActiveScriptSite.cpp, 737, Not found. (0x8004000B)
    Next Mileage Status Date, PropertyDefCalculatedValue, 10, Not found. (0x8004000B)
    MNullPropagatingDispatchImpl.h, 126, Not found. (0x8004000B)
    MNullPropagatingDispatchImpl.h, 173, Not found. (0x8004000B)
    CoPropertyValues.cpp, 347, Not found. (0x8004000B)
    (M-Files 22.6.11534.5 2023-02-06T07:46:19.935Z)

    Job type: Recalculate

  • When i try start operation recalulate i got this error:

  • Could it be that some of your objects don't have a workflow or state?

  • Thank you all for helping. We find solutions and solve problems.