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 "


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)