Automatic Field Population Options

<< Click to Display Table of Contents >>

Navigation:  Options > Data input >

Automatic Field Population Options

Automatic Field Population Options

Expression → Field List

This option allows to define rules to automatically populate specific fields in Data Input Form

Any entry in the list has the syntax:

[@<filter@>]<expression> -> [@separator@]<field>

[@<filter@>]

Optional. This condition can be applied BEFORE executing the <expression>
The rules for this condition are the same as those described for the "Data Input → Avoid Duplicated IDs → Except when ..." option

<expression>

it is a valid Variant Note expression

[@separator@]

Optional. This paramenteris considered only for expressions of type SELECT, and allows to insert the value calculated by the SELECT expression in APPEND to the existing value of the <field>, preceded by the string declared as @separator@.
When evaluated, if the original field value is not empty and if the actual SELECT value is not empty, the SELECT return value is appended in this way:

<original field value><separator><new SELECT evaluated value>

<field>

it is a DOCUMENT table field name

The expressions are resolved in a top-down order, so the expressions at lower levels may override the values written by the expressions at higher levels.

The input to the scripts (defined with a .VBSCRIPT-type expression) is the SAME of the OnOK.LST script.

Example1

suppose to define following rules:

.VBSCRIPT MyscriptForDescription.LST->DESCRIPTION

SELECT $LASTREV(APPROVED_BY)->@ Last Approver:@NOTES

let's write the script MyscriptForDescription.LST as follows:

'.x64

.VBSCRIPT
Sub Main()
 DBWInit(TRUE)
 state = DBWInput("STATE")
 if State="RELEASED" then
  DBWOutput "DESCRIPTION", "This is a RELEASED document" ,ForWriting
  DBWOutput "NOTES","" ,ForAppending
 elseif State="OBSOLETE" then
  DBWOutput "DESCRIPTION","This is an OBSOLETE document" ,ForWriting
  DBWOutput "NOTES","Please don't use this document in production !" ,ForAppending
 else
  DBWOutput "DESCRIPTION","This document is still NOT APPROVED" ,ForWriting
  DBWOutput "NOTES","Please don't use this document in production !" ,ForAppending
 end if
End sub

The intent of such script is to automatically populate the fields DESCRIPTION and NOTES based on the value of the STATE field.

The effect will be (starting from a RELEASED document):

images_autoFieldPopulation1

after the creation of a new revision:

images_autoFieldPopulation2

and when freezing the document:

images_autoFieldPopulation3

Example2

Only for assembly documents, calculate the SUM of all the 1st level child components weights and put the value into the WEIGHT field:

@T=A@select sum(weight) from document join parent_child on (unique_id=child_unique_id and T='P' and parent_unique_id=$(UNIQUE_ID))->WEIGHT