Removing existing values on a replace
To remove existing values on a replace, you can include blank elements
in the import XML. For example,
<Attribute1/>
in the xml does clear the
Attribute1 value.
You can also use the preImport
script hook.
This script hook enables you to access the existing Optiva object, before the XML is imported. In this example, the script
hook removes all the ingredient lines from the formula before the import. This ensures that the
ingredient lines are completely replaced during the import.
Option Strict Off
Imports System
Imports System.Data
Imports System.Diagnostics
Class HookScript
Inherits FcProcFuncSetEventHook
Function preImport() As Long
Dim formulaDs as DataSet = ObjectDataSet("", "", "HEADER;INGR") 'get from
bug
Dim ingrTableName as String = DataSetTableName("", "", "INGR")
'Get the ingredient table
Dim ingrTable as DataTable = formulaDs.Tables(ingrTableName)
'Now, clear it out, cannot use clear, need to delete the rows
For i as Integer = ingrTable.Rows.Count - 1 to 0 Step -1
ingrTable.Rows(i).Delete
Next
Return 1
End Function
End Class
Another option is to modify the XML that is being imported before the import
takes place. Elements can be added and removed using the context property _XMLSTR
. Unlike other properties, _XMLSTR
is read/write
.
Option Strict Off
Imports System
Imports System.Data
Imports System.Diagnostics
Class HookScript
Inherits FcProcFuncSetEventHook
Function preImport() As Long
Dim xmlStr as String = _XMLSTR
'now, set the new one
_XMLSTR = "<root><branch>01</branch><branch>02</branch></root>"
Return 1
End Function
End Class