Dynamic expressions allow us to automatically fill in the value of a field with simple Python commands. From dynamic expressions, we can access values stored in document properties or in other fields.
Dynamic expressions can be added from the field settings.
Click on Edit to open the editor and type your dynamic expression.
Some dynamic expressions and useful examples are listed below.
fil.filename #returns the uploaded file name sourcemetadata = filename
fil.life_cycle_state.name #returns the name of the current lifecycle state the doc is in. sourcemetadata = charact.ocr1
fil.author #returns the username of the document author. sourcemetadata = charact.ocr1
fil.author.first_name #returns the name of the document author. sourcemetadata = charact.ocr1
fil.creation_date #returns the creation date of the document. sourcemetadata = charact.ocr1
fil.version #returns the current version of the document. sourcemetadata = charact.ocr1
fil.serie.label #returns the space in which the document is located. sourcemetadata = charact.ocr1
fil.uuid #returns the internal document id
fil.validation_date #returns the validation date
You can also get values from other fields. The following shows how.
fil.gmv('metadata.Factura_ImporteFactura') #the internal name of the field in quote marks (metadatatype)
It is also possible to use Python expressions to manipulate values, for example, if we want to keep the name of the file, but without the .pdf extension, we apply the Python function .replace()
fil.filename.replace(".pdf"," ") #delete .pdf by replacing it
Assign values according to conditions
In dynamic expressions, you can use conditions so that the field takes one value or another. You can do this by following the structure we provide below:
X and A or B
Where X is the condition, A is the value the field takes if the condition is met, and B is the value if the condition is not met.
For example, we want to assign a value depending on the form. If the form is "Invoice," we want to assign a value of 1 to the field. In any other scenario, the field should take the value 0. Our condition would look like this:
fil.doctype.name == "Invoice" and 1 or 0