Scripts used in the creation of flows
Below is a compilation of the scripts currently being used in Waidok projects:
- Replace characters in a variable. In the example, replace all occurrences of "cat" with "dog" using a regular expression with the g (global) flag. You can find an explanation and examples of regular expressions here: https://4geeks.com/es/lesson/regex-tutorial-regular-expression-ejemplo.
let newText = text.replace(/cat/g, "dog");
var string = getVariable('strOCRCertificateNumber')
string.replace(/[./\\s]/g, "");
- Assign values from a property (list type) to a variable. In the example, the value of the "propertyName" property is assigned to the current variable. The property value is extracted from the document metadata that has been previously saved in the "collectionMetadataObject" object-type variable.
var msg = getVariable('objMetadatosColección')
var metadata = msg['Metadata']
metadata['propertyName'].slice(2, -2);
- Assign values from a property (not a list type) to a variable. In the example, the value of the "propertyName" property is assigned to the current variable. The property value is extracted from the document metadata that has been previously saved in the object-type variable "objMetadataCollection." Finally, the first two characters and the last two characters of the list value are removed, since list-type values are saved as an array that inserts square brackets and quotation marks in each value, and these must be removed in order to insert them into the variable.
var msg = getVariable('collectionMetadataObject')
var metadata = msg['Metadata']
metadata['propertyName']
- Retrieve the value of a variable in an activity.
getVariable('variableName')
- Retrieve an element from a master table column. First, we must assign the value of a row in the master table to an Object type variable with a Search master table workflow activity. Inthe example, the value of the "propertyName" property is assigned to the current variable. The property value is extracted from the document metadata that has previously been saved in the "collectionMetadataVariable" variable. In the second line of code, the number of the column from which the data is to be extracted is placed in square brackets. The first column is 0, the second is 1, the third is 2, etc.
var msg = getVariable('objFilaTablaMaestra')
msg[0]
- Assign a NIF value from Invofox to a variable. NIF numbers processed by Invofox are formatted with international coding, i.e., they insert the country code at the beginning of the number in two characters. So, if we want to be able to compare them with a master table and allow their manual insertion, we must always insert the value without the country code in the variable. Previously, we must assign the document metadata in the Output of an activity to an object-type variable. In the example, objMetadata
var msg = getVariable('objMetadata')
var metadata = msg['Metadata']
if (metadata['PropertyNameNIF'].toString().length > 9)
metadata['PropertyNameNIF'].toString().substring(2)
else
metadata['PropertyNameNIF'].toString();
- Examples of conditions for Decision activity.
- Value of a variable other than 0.
getVariable('variableName') != 0
-
- Value of a variable equal to a value.
getVariable('variableName') == "value to compare"
-
- Value of a variable greater than or equal to a number. In the example, greater than or equal to 2000.
getVariable('variableName') >= 2000
- Retrieve Waidok internal metadata values. First, we must assign the document metadata in the Output of an activity to an object-type variable. In the example, objMetadata.
- Retrieve the file name.
var msg = getVariable('objMetadata')
msg['fileName']
-
- Retrieve the user who registered the file in Waidok (owner).
var msg = getVariable('objMetadata')
msg['Owner']
- Retrieve a user registered in Waidok from a property with their name. Please note that the property from which the data is retrieved is a List property with the same names as the users registered in the tool.Previously, we must assign the document metadata in the Output of an activity to an object-type variable. In the example, objMetadata.
var msg = getVariable('objMetadata')
var metadata = msg['Metadata']
var reviewer = metadata['InternalPropertyName'].toString().substring(2)
reviewer.substring(0, reviewer.length - 2)
- Assign the AI feedback information to a table in a label.
const ai = JSON.parse(getVariable("AiResponse"))[0];
const transformed = ai.items.map(it => ({
1: it.description,
2: it.heat_number
}));
return transformed;
- Assign the first sorted value of a result from multiple rows of a master table to a variable. In the example, multiple rows from a master table have been previously retrieved into an object-type variable called objMasterTableMetadata.
const data = getVariable('objMetadataMasterTable')
// Sort by the first element
data.sort((a, b) => Number(a[0]) - Number(b[0]));
return data[0];
- When a task is completed and we want to enter the date it was completed. It will collect, for example, when someone has approved a document and record it in a property.
new Date();
- Customization of the body of a notification email. Previously, the values of the document properties must be assigned to an object-type variable. In the example, objMetadata.
var msg = getVariable('objMetadata')
var metadata = msg['Metadata']
'This is an example of an email body that collects data from an invoice, such as its number: ' + metadata['InvoiceNumberPropertyName'] + ', from the supplier ' + metadata['SupplierPropertyName'] + ', dated ' + metadata['DatePropertyName'] + '.'
No comments to display
No comments to display