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

Creating Object type under a class using script?

Hello All,

I am trying to create an object type called "Dose Confirmation / Reminder" under a class of "Patient".

The required fields to create the "Dose confirmation":

The information under "Patient" class: (In addition to name and basic information)




I want to create a "Dose confirmation" automatically whenever the "Patient" statues changes to " Treatment Started "

Meaning:

Test is a patient. and once we changes his status to "Treatment started"  that field "Dose Reminders" get created with an initial dose after the "Treatment Date" Property in the patient class.






It is easier to create an object of the same class, like creating future doses from an initial dose date. Already did that as shown in the pics "Dose confirmed" will create another dose to be scheduled.
But creating a class as object type under a totally different class "Patient" is it even possible?

Here is the code i am working on: (But showing errors as "Not found" and "Mistype match" Which is reasonable.. because i don't know which one I should add, save, or search for)

``` 

Option Explicit

Dim iPDPatient: iPDPatient = 1170 'Patient Property Definition ID
Dim iPDName: iPDName = 1032 'Name Property Definition ID
Dim iPDDose: iPDDose = 1092 'Dose Property Definition ID
Dim iPDDrug: iPDDrug = 1133 'Drug Property Definition ID
Dim iPDDueDate: iPDDueDate = 1083 'Due Date Property Definition ID
Dim iPDInitiateTreatment: iPDInitiateTreatment = 1047 'Next Dose After Property Definition ID

Dim iOTDoseReminder: iOTDoseReminder = 118 'Dose Reminder Object Type
Dim iCLPatient: iCLPatient = 4 'patient Class ID

Dim iPDState: iPDState = 39 'State Property Definition
Dim iPDStateDoseScheduled: iPDStateDoseScheduled = 120 'State Dose Scheduled Property Definition
Dim iPDWorkFlow: iPDWorkflow = 38 'Workflow Property Definition
Dim iPDDoseReminderWorkflow: iPDDoseReminderWorkflow = 10 'Dose Reminder Workflow Property Definition


' Create a new Dose Reminder
Dim oPropVals: Set oPropVals = CreateObject("MFilesAPI.PropertyValues")
Dim oOnePropVal: Set oOnePropVal = CreateObject("MFilesAPI.PropertyValue")

' Class = Patient ? or shall i search in Dose reminder class?
oOnePropVal.PropertyDef = 100
oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iCLPatient
oPropVals.Add -1, oOnePropVal

' Patient
oOnePropVal.PropertyDef = iPDPatient
oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDPatient).TypedValue.Value
oPropVals.Add -1, oOnePropVal

' Drug
oOnePropVal.PropertyDef = iPDDrug
oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDDrug).TypedValue.Value
oPropVals.Add -1, oOnePropVal

' Dose
oOnePropVal.PropertyDef = iPDDose
oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDDose).TypedValue.Value
oPropVals.Add -1, oOnePropVal

' Due Date = After Infi weeks
oOnePropVal.PropertyDef = iPDDueDate
oOnePropVal.TypedValue.SetValue MFDatatypeDate, DateAdd("d",7*PropertyValues.SearchForProperty(iPDInitiateTreatment).TypedValue.Value,PropertyValues.SearchForProperty(iPDDueDate).TypedValue.Value)
oPropVals.Add -1, oOnePropVal

' Assign workflow -  Workflow
oOnePropVal.PropertyDef = iPDWorkFlow
oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iPDDoseReminderWorkflow
oPropVals.Add -1, oOnePropVal

' Assign workflow state -  Added
oOnePropVal.PropertyDef = iPDState
oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iPDStateDoseScheduled
oPropVals.Add -1, oOnePropVal

' Not single file document
oOnePropVal.PropertyDef = 22
oOnePropVal.TypedValue.SetValue MFDataType.MFDatatypeBoolean, false
oPropVals.Add -1, oOnePropVal

Dim oObjectVersionAndProperties: set oObjectVersionAndProperties = Vault.ObjectOperations.CreateNewObject(iOTDoseReminder, oPropVals, nothing, nothing)
Call Vault.ObjectOperations.CheckIn(oObjectVersionAndProperties.ObjVer)

```

Parents
  • There is an update... I think i am going in the right direction... but i have no idea what i am doing to be honest.

    The new code:

    ``` 

    Option Explicit

    Dim iPDPatient: iPDPatient = 1170 'Patient Property Definition ID
    Dim iPDDueDate: iPDDueDate = 1083 'Due Date Property Definition ID
    Dim iPDDrug: iPDDrug = 1133 'Drug Property Definition ID
    Dim iPDDose: iPDDose = 1092 'Dose Property Definition ID
    Dim iPDTreatmentInitiationDate: iPDTreatmentInitiationDate = 1047 ' Treatment start Property Definition ID

    Dim iOTDose: iOTDose= 118 'Dose Object Type
    Dim iCLDose: iCLDose= 11 'Dose Class ID

    Dim iPDState: iPDState = 39 'State Property Definition
    Dim iPDStateDosePending: iPDStateDosePending = 120 'State Dose Pending Property Definition
    Dim iPDWorkFlow: iPDWorkflow = 38 'Workflow Property Definition
    Dim iPDDoseWorkflow: iPDDoseWorkflow = 106 'Dose Workflow Property Definition


    ' Create a new Dose
    Dim oPropVals: Set oPropVals = CreateObject("MFilesAPI.PropertyValues")
    Dim oOnePropVal: Set oOnePropVal = CreateObject("MFilesAPI.PropertyValue")

    ' Class = Dose
    oOnePropVal.PropertyDef = 100
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iCLDose
    oPropVals.Add -1, oOnePropVal

    ' Patient
    oOnePropVal.PropertyDef = iPDPatient
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, Objver.ID
    oPropVals.Add -1, oOnePropVal

    ' Drug
    oOnePropVal.PropertyDef = iPDDrug
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDDrug).TypedValue.Value
    oPropVals.Add -1, oOnePropVal

    ' Dose
    oOnePropVal.PropertyDef = iPDDose
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDDose).TypedValue.Value
    oPropVals.Add -1, oOnePropVal

    ' Due Date = Treatment Initiation Date
    oOnePropVal.PropertyDef = iPDDueDate
    oOnePropVal.TypedValue.SetValue MFDatatypeDate, DateAdd("d",7*PropertyValues.SearchForProperty(iPDTreatmentInitiationDate).TypedValue.Value)
    oPropVals.Add -1, oOnePropVal

    ' Assign workflow - Dose Workflow
    oOnePropVal.PropertyDef = iPDWorkFlow
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iPDDoseWorkflow
    oPropVals.Add -1, oOnePropVal

    ' Assign workflow state - Pending
    oOnePropVal.PropertyDef = iPDState
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iPDStateDosePending
    oPropVals.Add -1, oOnePropVal

    ' Not single file document
    oOnePropVal.PropertyDef = 22
    oOnePropVal.TypedValue.SetValue MFDataType.MFDatatypeBoolean, false
    oPropVals.Add -1, oOnePropVal

    Dim oObjectVersionAndProperties: set oObjectVersionAndProperties = Vault.ObjectOperations.CreateNewObject(iOTDose, oPropVals, nothing, nothing)
    Call Vault.ObjectOperations.CheckIn(oObjectVersionAndProperties.ObjVer)

    ```

    But i get this error now: (Didn't get "not found" and "misstype match"  errors now)


    Any idea how to deal with this one?

    the error text:
     
    CoScriptObjectFactory.cpp, 465, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    ScriptErrorHelper.cpp, 96, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MDispatchExImpl.h, 694, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MDispatchExImpl.h, 994, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataCardAction.cpp, 386, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataCardAction.cpp, 570, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataEditor.cpp, 2959, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataModel.cpp, 4244, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataModel.cpp, 4681, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    ElectronicSignatureUIHelper.cpp, 235, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataModel.cpp, 12170, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    CoVaultMountingDocumentOperations.cpp, 3204, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    DocumentCache.cpp, 11300, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    DocumentCache.cpp, 11409, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    DocumentCache.cpp, 19577, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperations.cpp, 12873, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperations.cpp, 7387, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MCallInLoop.h, 712, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 4158, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 3719, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 9397, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 10064, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 27741, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 2908, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 3120, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 3540, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 4379, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    VaultScriptSessionTemplates.cpp, 510, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    CoActiveScriptSite.cpp, 895, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    CoActiveScriptSite.cpp, 737, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    Treatment Started, StateAction, 45, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    MErrorHelper.cpp, 2457, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    (M-Files 21.9.10629.5)

Reply
  • There is an update... I think i am going in the right direction... but i have no idea what i am doing to be honest.

    The new code:

    ``` 

    Option Explicit

    Dim iPDPatient: iPDPatient = 1170 'Patient Property Definition ID
    Dim iPDDueDate: iPDDueDate = 1083 'Due Date Property Definition ID
    Dim iPDDrug: iPDDrug = 1133 'Drug Property Definition ID
    Dim iPDDose: iPDDose = 1092 'Dose Property Definition ID
    Dim iPDTreatmentInitiationDate: iPDTreatmentInitiationDate = 1047 ' Treatment start Property Definition ID

    Dim iOTDose: iOTDose= 118 'Dose Object Type
    Dim iCLDose: iCLDose= 11 'Dose Class ID

    Dim iPDState: iPDState = 39 'State Property Definition
    Dim iPDStateDosePending: iPDStateDosePending = 120 'State Dose Pending Property Definition
    Dim iPDWorkFlow: iPDWorkflow = 38 'Workflow Property Definition
    Dim iPDDoseWorkflow: iPDDoseWorkflow = 106 'Dose Workflow Property Definition


    ' Create a new Dose
    Dim oPropVals: Set oPropVals = CreateObject("MFilesAPI.PropertyValues")
    Dim oOnePropVal: Set oOnePropVal = CreateObject("MFilesAPI.PropertyValue")

    ' Class = Dose
    oOnePropVal.PropertyDef = 100
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iCLDose
    oPropVals.Add -1, oOnePropVal

    ' Patient
    oOnePropVal.PropertyDef = iPDPatient
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, Objver.ID
    oPropVals.Add -1, oOnePropVal

    ' Drug
    oOnePropVal.PropertyDef = iPDDrug
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDDrug).TypedValue.Value
    oPropVals.Add -1, oOnePropVal

    ' Dose
    oOnePropVal.PropertyDef = iPDDose
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, PropertyValues.SearchForProperty(iPDDose).TypedValue.Value
    oPropVals.Add -1, oOnePropVal

    ' Due Date = Treatment Initiation Date
    oOnePropVal.PropertyDef = iPDDueDate
    oOnePropVal.TypedValue.SetValue MFDatatypeDate, DateAdd("d",7*PropertyValues.SearchForProperty(iPDTreatmentInitiationDate).TypedValue.Value)
    oPropVals.Add -1, oOnePropVal

    ' Assign workflow - Dose Workflow
    oOnePropVal.PropertyDef = iPDWorkFlow
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iPDDoseWorkflow
    oPropVals.Add -1, oOnePropVal

    ' Assign workflow state - Pending
    oOnePropVal.PropertyDef = iPDState
    oOnePropVal.TypedValue.SetValue MFDatatypeLookup, iPDStateDosePending
    oPropVals.Add -1, oOnePropVal

    ' Not single file document
    oOnePropVal.PropertyDef = 22
    oOnePropVal.TypedValue.SetValue MFDataType.MFDatatypeBoolean, false
    oPropVals.Add -1, oOnePropVal

    Dim oObjectVersionAndProperties: set oObjectVersionAndProperties = Vault.ObjectOperations.CreateNewObject(iOTDose, oPropVals, nothing, nothing)
    Call Vault.ObjectOperations.CheckIn(oObjectVersionAndProperties.ObjVer)

    ```

    But i get this error now: (Didn't get "not found" and "misstype match"  errors now)


    Any idea how to deal with this one?

    the error text:
     
    CoScriptObjectFactory.cpp, 465, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    ScriptErrorHelper.cpp, 96, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MDispatchExImpl.h, 694, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MDispatchExImpl.h, 994, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataCardAction.cpp, 386, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataCardAction.cpp, 570, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataEditor.cpp, 2959, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataModel.cpp, 4244, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataModel.cpp, 4681, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    ElectronicSignatureUIHelper.cpp, 235, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MetadataModel.cpp, 12170, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    CoVaultMountingDocumentOperations.cpp, 3204, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    DocumentCache.cpp, 11300, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    DocumentCache.cpp, 11409, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    DocumentCache.cpp, 19577, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperations.cpp, 12873, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperations.cpp, 7387, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    MCallInLoop.h, 712, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 4158, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 3719, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 9397, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 10064, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 27741, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 2908, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 3120, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 3540, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 4379, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((Treatment Started, StateAction: 110-1-10)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    VaultScriptSessionTemplates.cpp, 510, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    CoActiveScriptSite.cpp, 895, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    CoActiveScriptSite.cpp, 737, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    Treatment Started, StateAction, 45, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    MErrorHelper.cpp, 2457, Wrong number of arguments or invalid property assignment: 'DateAdd' (0x80040008)
    (M-Files 21.9.10629.5)

Children