Script Node Writable Original

This is an extension of script node, and can be used to create or update a node.

ScriptNodeWritableOriginal is returned from the application calls getNodeWritable() and newNode(), the former taking the identity of the node to be updated, the latter the identity of the type node.

ScriptNodeWritableOriginal provides all the same methods as ScriptNodeWritableDerived and ScriptNode, though it reads and modifies the original rather than the derived data. It returns edit extensions. Because of the way that data is managed internally, a node can not predictably be read once you have started writing to it. Specifically, the listMembers, getMember, getValue, getScale and getTarget methods will not return predictable results after the first setMember, setValue, setScale or setTarget has taken place for the same member type. For the same reason, you need to be cautious of the use of sequence number on the various setXXX methods:

  • For new nodes, where cardinality is 1, use the setXXX methods without a sequence number.
  • For new nodes, where cardinality is 0 or more than 1, use the setXXX methods with a sequence number of 0 to add to the list.
  • For existing nodes, where cardinality is 1, use the setXXX methods without a sequence number.
  • For exsing nodes, where cardinality is 0 or more than 1, use the setXXX methods with a sequence number to update existing member, or 0 to add to the list.
  • If you want to re-order the list, the safest way to do it is to read all the members (using listMembers()) and then write them all back (using deleteAll() and addAll()).

All calls that involve setting data must be finished by the apply() method, which actually writes the data back to the database. After apply() has been called, the object's state may be inconsistent with the database, and the object should be re-retrieved if still required.

In addition to the methods from ScriptNodeWritableDerived and ScriptNode, ScriptNodeWritableOriginal provides:

boolean = setNodeReference(nodeReference) Set the node reference.

Return true if OK, else set the error on the object.

You must call setNodeReference() when creating a new node. You must not call it when updating an existing node.

boolean = apply(update)

Write changes to the database.

If update is true, also update the node to ensure it is derived and so that it can be used for further updates. update is optional and defaults to true. If you do not require that the node is made up to date before continuing, use update(false).

Return true if OK, else set the error on the object.

If it returns OK, the version reference for the redirect node, if any, will be available in the nodeVersionReferenceRedirect attribute.