Question
When an error occurs in a script, we would like to send a message to Microsoft Teams including the content of the error that occurred.
In this case, is it possible to dynamically edit the content of the message to be sent?
Background
In the script we are developing, we expect the following process when an error occurs.
1. Catch the error at the Catch node of Monitor Exception operation.
2. Read a JSON file in the subsequent Execute Post operation.
3. Send a message to Microsoft Teams using the existing connector.
*In step 2, "File" is selected as input source in the Request Settings.
Currently, only messages pre-described in JSON file can be sent out, and messages including error contents dynamically cannot be sent.
Answer
The following is a guide on how to dynamically specify the message to be sent when a JSON file is specified as the request data for Execute POST operation.
Regarding how to edit JSON files, HULFT Square does not have a dedicated component that reads JSON files.
As an alternative, it is possible to edit JSON files by reading the files as variable length files, mapping data values, and writing them out.
Therefore, it would be possible to dynamically change the message to be sent by entering a specific string in JSON files in advance and replacing the error message with the specific string.
Please try the following procedure to see if you can implement this.
- Enter a specific string in the area of a JSON file where you want to enter the message part and save the JSON file compressed into a single line in the storage.
- Create a script variable to store error message.
- Place the Read Variable-Length File component to read the saved JSON file as a variable length file
To read one line of JSON data as one field of data, set the variable length file read format to one field per record and the delimiter character list to characters not used in the data.
- Place the Write Variable-Length File component and add mapping
To write the data read as a variable length file as a single line of JSON data, the variable length file write format should be one record and one field.
- Remove newline code from the error message to be inserted into JSON file
To store the error message in one line of data, replace regular expressions for newline with [String]-[Conversion]-[Replace by Regular Expression] logic and store them in the script variable created in step 2.
- Replace a script variable with a specific string in the data
With [String]-[Conversion]-[Replace Each String] logic, replace the specific string with the error message, and map them as fixed-length file writing data.
In this case, set the setting items to [partial match] and [partial replacement].
- Sending the created JSON file by POST execution process
Set "File" as data input source in the request settings for Execute POST operation, then read and send the JSON file written in step 4.
For details on the Variable Length File Connector, please refer to the following manual pages.
◇Documentation
Connector Operation Guide - Variable-Length
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/file_VariableLength.htm
Variable Length Write Wizard
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/variable_put_wizard.htm
Comments
0 comments
Article is closed for comments.