1C Incoming Invoice (COM)#
Let's consider an example of a robot that creates an incoming invoice in the 1C program. The source data for this project is the file "Supplier Order". The work is based on using a COM connection to the 1C application.
This project demonstrates loading data from PDF or Excel. To see how the work with PDF occurs, you need to connect the "Start Process" block and the left block "Get File Path".
To check the work with loading from an Excel file, you need to connect the "Start Process" block and the right block "Get File Path".
The robot project consists of four diagrams and four files: two txt, pdf, and xlsx. The file "QueryTemplate.txt" contains a query template written in the 1C language. There is a separate diagram for loading data from pdf and xlsx files.
The main diagram looks like this (for convenience, the blocks of the diagram are numbered):
- "Start" Block (any diagram starts from this block).
- "Get File Path" Block retrieves the full path to the file with the specified name. The following properties are specified for these blocks:
- Folder Path (the path to the folder where the required file is located; if the property is empty, the folder where this project is located will be taken);
- File Name (the name of the file along with its format).
In this case, two "Get File Path" blocks are used in parallel: one for the pdf file format, the other for the xlsx file format.
- "Process" Block allows creating scenarios consisting of several diagrams. The execution of the scenario will continue from the "Start" block of the specified project diagram. The execution of the scenario will return to the current block and continue in the current diagram as soon as the "End" block is reached in the external diagram. For the "Process" block, the property "Diagram Name" is specified (the name of the diagram file where the scenario will continue execution).
In this case, as above, two "Process" blocks are used in parallel: one for loading data from the pdf file, the other for loading data from the xlsx file.
- "Process" Block located below allows creating another scenario that is common for the two scenarios described above. This process is responsible for adding the invoice to 1C. For the "Process" block, the property "Diagram Name" is also specified (the name of the diagram file where the scenario will continue execution).
Diagram "LoadDataFromPDF"
- "Start" Block (any diagram starts from this block).
- "Log" Block allows outputting arbitrary messages and/or variable values to the log during the robot's scenario execution. For this block, the property "Value" is specified. The text constant is indicated in quotes, and the variable name starts with the $ symbol. That is, this block records a message in the robot's log about loading the selected file specified by the variable.
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, two expressions are used.
- "Extract Table" Block allows extracting the specified table from a pdf file. The following properties are specified for this block:
- File Name;
- Page Number (the page number from which the text will be extracted from the table);
- Table Number on the Page (the table number on the page from which the text needs to be extracted).
- "For Each Loop" Block iterates through all rows of the data table.
- "Get Text from Page" Block allows reading text from the specified page of the pdf file. The following properties are specified for this block:
- File Name;
- Page Number (the page number from which the text will be extracted);
- Result (returns the extracted text from the page).
- "Find Substring Between Two Substrings" Block allows finding a substring in the text that is located between two other substrings. There should be as many of these blocks as there are substrings to find. In this case, two "Find Substring Between Two Substrings" blocks are used: for the substring "Executor" and the substring "Order". The properties of the blocks specify:
- Text (input string);
- Left Part (left search substring);
- Right Part (right search substring).
- "Condition" Block checks the specified condition for truth, after which the execution of the scenario continues towards the "Yes" exit (if the condition is met) or towards the "No" exit (if the condition is not met).
The condition is written in the format: "variable" equals (==)/ greater than (>)/ less than (<) "value".
For example: $a == "Hello", that is, if the value of the variable $a is equal to "Hello", then the "Yes" exit, otherwise – the "No" exit.
$Result > 5, that is, if the value of the variable $Result is less than 5, then the "Yes" exit, otherwise – the "No" exit.
In this case, the condition is set as: $Row[0] == $index, that is, if the value of cell 0 is equal to the variable $index, then the "Yes" exit, otherwise – the "No" exit.
- "Add Row" Block allows adding a row to the data table. In this case, the following properties are specified:
- Table (the data table to which the row is added);
- Row Number (returns the number of the added row, numbering starts from 0).
- "Write Value to Cell" Block allows writing a value to a cell in the data table. In this case, three such blocks are used for different variables: $Row[2], $Row[3], and $Row[5].
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, one expression is used.
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, one expression is used.
- "End" Block (this block ends the execution of the scenario or returns the subprocess diagram to the main process).
Diagram "LoadDataFromXLSX"
- "Start" Block (any diagram starts from this block).
- "Log" Block allows outputting arbitrary messages and/or variable values to the log during the robot's scenario execution. For this block, the property "Value" is specified. The text constant is indicated in quotes, and the variable name starts with the $ symbol. That is, this block records a message in the robot's log about loading the selected file specified by the variable.
- "Open Document" Block allows opening an Excel document. The following properties are specified for this block:
- File Path (the path to the Excel document that needs to be opened);
- Excel Reference (returns a reference to the process of handling the Excel document);
- Document Reference (returns a reference to the opened Excel document that is currently being worked on).
- "Get Cell Value" Block allows reading a value from a cell in the Excel document. In this case, two "Get Cell Value" blocks are used for different rows and columns. The following properties are specified for this block:
- Document Reference (returns a reference to the opened Excel document that is currently being worked on);
- Sheet (the ordinal number or name of the sheet where the required cell is located);
- Row (the row number where the required cell is located);
- Column (the column number where the required cell is located);
- Result (returns the content of the cell of the same data type as in the Excel document).
- "Find Substring Between Two Substrings" Block allows finding a substring in the text that is located between two other substrings. There should be as many of these blocks as there are substrings to find. In this case, two "Find Substring Between Two Substrings" blocks are used: for the substring "Executor" and the substring "Order". The properties of the blocks specify:
- Text (input string);
- Left Part (left search substring);
- Right Part (right search substring).
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, one expression is used.
- "Get Cell Value" Block allows reading a value from a cell in the Excel document. The following properties are specified for this block:
- Document Reference (returns a reference to the opened Excel document that is currently being worked on);
- Sheet (the ordinal number or name of the sheet where the required cell is located);
- Row (the row number where the required cell is located);
- Column (the column number where the required cell is located);
- Result (returns the content of the cell of the same data type as in the Excel document).
- "Condition" Block checks the specified condition for truth, after which the execution of the scenario continues towards the "Yes" exit (if the condition is met) or towards the "No" exit (if the condition is not met).
The condition is written in the format: "variable" equals (==)/ greater than (>)/ less than (<) "value".
For example: $a == "Hello", that is, if the value of the variable $a is equal to "Hello", then the "Yes" exit, otherwise – the "No" exit.
$Result > 5, that is, if the value of the variable $Result is less than 5, then the "Yes" exit, otherwise – the "No" exit.
- "Close Document" Block allows closing the Excel document. The following properties are specified for this block:
- Excel Reference (returns a reference to the process of handling the Excel document);
- Document Reference (returns a reference to the opened Excel document that is currently being worked on).
- "Get Cell Value" Blocks allow reading a value from a cell in the Excel document. In this case, two "Get Cell Value" blocks are used for different rows and columns. The following properties are specified for this block:
- Document Reference (returns a reference to the opened Excel document that is currently being worked on);
- Sheet (the ordinal number or name of the sheet where the required cell is located);
- Row (the row number where the required cell is located);
- Column (the column number where the required cell is located);
- Result (returns the content of the cell of the same data type as in the Excel document).
- "Add Row" Block allows adding a row to the data table. The following properties are specified for this block:
- Table (the data table to which the row is added);
- Row Number (returns the number of the added row).
- "Write Value to Cell" Block allows writing a value to a cell in the data table. In this case, three such blocks are used for different columns and values. The following properties are specified for this block:
- Table (the data table where the value needs to be written);
- Row (row number);
- Column (column number, numbering starts from 0);
- Value (the value that needs to be written).
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, one expression is used.
- "End" Block (this block ends the execution of the scenario or returns the subprocess diagram to the main process).
Diagram "AddingInvoice"
- "Start" Block (any diagram starts from this block).
- "Log" Block allows outputting arbitrary messages and/or variable values to the log during the robot's scenario execution. For this block, the property "Value" is specified. Here, this block records a message in the robot's log "Adding invoice".
- "Read File" Block allows reading the contents of a text file into a variable. The following properties are specified for this block:
- File Name (the name of the text file whose contents need to be read);
- Encoding (the encoding of the file);
- Result (returns the contents of the file).
- "Replace Substring" Block allows replacing one substring with another in the text. In this case, two "Replace Substring" blocks are used: for "Customer" and for "Supplier". The following properties are specified for these blocks:
- Text (input string);
- Search Substring (the string that needs to be replaced);
- Inserted Substring (the string to replace all occurrences of the search substring);
- Result (the new string in which all occurrences of the specified string are replaced with another specified string).
- "For Each Loop" Block iterates through all rows of the data table.
- "Join Text" Block allows joining all elements of strings, placing a specified separator between them. The following properties are specified for this block:
- List of Text Parts (a list of strings that need to be joined into a text string);
- Separator (the text used as a separator);
- New Line (a set flag that includes a function where a new line will be used as a separator);
- Result (the resulting string).
- "Replace Substring" Block allows replacing one substring with another in the text. The following properties are specified for this block:
- Text (input string);
- Search Substring (the string that needs to be replaced);
- Inserted Substring (the string to replace all occurrences of the search substring);
- Result (the new string in which all occurrences of the specified string are replaced with another specified string).
- "Connect" Block allows creating a connection. The following properties are specified for this block:
- Connection String (the connection string to 1C);
- User (username for authorization);
- Password (password for authorization);
- Visibility (a set flag that enables the visibility of the 1C user window);
- Connection (returns the connection object to 1C).
- "Execute Code" Block allows executing code on the server. The following properties are specified for this block:
- Connection (the connection object to 1C);
- Query (the query executed in the 1C language).
- "Close Connection" Block allows closing the connection to the 1C server. The property "Connection" (the connection object to 1C) is specified for this block.
- "Log" Block allows outputting arbitrary messages and/or variable values to the log during the robot's scenario execution. For this block, the property "Value" is specified: $ErrorMassage. That is, the robot's log outputs an error message.
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, two expressions are used.
- "Add Element to List" Block allows adding the specified element to the end of the list. The following properties are specified for this block:
- List (the list to which the new element needs to be added);
- Element (constant, variable, or result of calculations that need to be added to the list).
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, two expressions are used.
- "Add Element to List" Block allows adding the specified element to the end of the list. The following properties are specified for this block:
- List (the list to which the new element needs to be added);
- Element (constant, variable, or result of calculations that need to be added to the list).
- "Execute Expression" Block starts the execution of one or more expressions in a language compatible with PowerShell. In this case, two expressions are used.
- "Add Element to List" Block allows adding the specified element to the end of the list. The following properties are specified for this block:
- List (the list to which the new element needs to be added);
- Element (constant, variable, or result of calculations that need to be added to the list).
- and 19. "End" Block (this block ends the execution of the scenario or returns the subprocess diagram to the main process).