"Insert" Function

Top  Previous  Next

Insert function inserts a new item node into the given ADOM and creates the specified sub nodes under it. If a similar node control expression is given, it first checks to see if any item node in the ADOM satisfies the condition in the expression. If no then a new item node is created.

Syntax:

Insert(adom-scope:adom-nametarget-subnodesvalues[similar-node-test-expression[replace]])

 

adom-scope

The scope of the ADOM. Values are "r" Request, "s" Session and "a" Application.

 

adom-name

The name of the ADOM.

 

target-subnodes

The names of the ADOM sub nodes that will be created and assigned values.

values

The values for the target adom sub nodes. If no source specifier is given for a symbol, the source is searched in "f:", "v:", "i:", "a:" order.

similar-node-test-expression

The expression that is tested against each item node of the ADOM till a match found. If no match is found a new Item node is inserted. If a match is found and if replace parameter is defined as true then the matched item node is updated. Otherwise no action is taken.

If no source specifier is given for a symbol in the where expression, the source is searched in "a:", "f:", "v:" and "i:" order.

replace

If where expression is defined and if there is a match, the values of matched ADOM sub nodes are updated with the source fields if the value of this parameter is true.

 

Examples:

Insert(s:cart, *, *) 

Insert a new item node into session ADOM cart and create a sub node under it for each process block field existing in the current process block and assign their values.

Insert(s:cart, *, *, ID = f:ID)

Check if an item node exists in the session ADOM cart whose sub node ID contains a value that is equal to the value of the process block field ID. If no, then insert a new item node into session ADOM cart and create a sub node under it for each process block field existing in the current process block and assign their values. If yes do nothing.

Insert(
  s:cart,
  [ID,   PRICE,   QTY,           TOTAL_PRICE               ],
  [f:ID, f:PRICE, nf:QTY+na:QTY, (nf:QTY+na:QTY) * nf:PRICE * v:DISCOUNT], 
  ID = f:ID, true
  )

 
id attribute

Each item node created is attached an attribute named id that contains a unique number for identification. This attribute can be used as the key to address the item node to update or delete.

Example:

Delete(s:cart, a:@id = f:@id)

 

See ADOM Item Id