Example of using To string action from Datetime package
- Updated: 2023/12/13
Example of using To string action from Datetime package
Build a bot that compares the current date with the expiration dates of products.
Prerequisites
You need sample inventory data with expiration dates. If you do not have any sample data, download this spreadsheet that contains sample inventory data with expiration dates.
In this example, the bot loops through a list of products in a spreadsheet and compares the expiration date of each product with the current date. If the dates match, the bot marks the product as expired.
Procedure
-
Create a new bot.
- On the left panel, click Automation.
- Click .
- In the Create Task Bot window, enter a name for the bot.
- Accept the default folder location: \Bots\
- To change the default bot storage location, click Choose and follow the prompts.
- Click Create and edit.
-
Dates in the sample data are specified in yyyy-MM-dd format. To compare each
date to the current date, you need to obtain the current date using the
System:Date variable and convert it to the yyyy-MM-dd
format. To do so, use the action and theSystem: Date variable.
- From the Actions panel, find and add action to the Bot editor.
- In Source date and time variable, click Variable, and enter $System:Date$. You can use the System: Date variable to get the current date.
- In Select date time format, click Custom format, and enter yyyy-MM-dd.
- In Assign the output to a variable, click (x) and create a string variable named currentDate.
- Save the changes.
-
Open the spreadsheet with the sample inventory data.
- From the Actions panel, find and add action to the Bot editor.
- In File path, click Desktop file and select the spreadsheet with the sample inventory data.
- Select Sheet contains a header.
- Select Specific sheet name and enter the sheet name. If you are using the sample spreadsheet downloaded from this page, specify inventory as the sheet name.
- In Create Excel session, click Local session and enter Default.
- Save changes.
-
Select the second row in the current spreadsheet.
- From the Actions panel, find and add action to the Bot editor.
- In Cell option, click Specific cell and then enter A2 in Cell name.
- In Session name, enter Default.
- Save changes.
-
Iterate through the rows in the spreadsheet and get the expiry date for each
product.
- From the Actions panel, find and add action to the Bot editor.
- In Iterator, choose .
- In Loop through, select the All rows variable.
- In Session name, enter Default.
- In Assign the current row to this variable, click Record, and click (x) to create a record variable named ExcelRow.
- Save changes.
-
Compare each expiry date with the current date.
- From the Actions panel, find and add action within the Loop action.
- In Source string, enter $currentDate$.
- In Compare to string, enter $ExcelRow[2]$.
- In Assign the output to variable, click (x) to create a Boolean variable named datesMatched.
- Save the changes.
-
Verify if the current date matches the expiry date of the current item.
- From the Actions panel, find and add action with the Loop action.
- In Condition, select .
- In Boolean variable, click True.
- In Operator, select Equals to(=).
- In Value, click Variable and enter $datesMatched$.
- Save the changes.
-
If the dates match, move the cursor to the end of the current row.
- From the Actions panel, find and add action within the If action.
- In Cell option, click Active cell and then select End of the row.
- In Session name, enter Default.
- Save changes.
-
If the dates match, mark the product as expired.
- From the Actions panel, find and add action within the if action.
- In Use, click Active cell.
- In Value to set, enter Yes.
- In Session name, enter Default.
- Save the changes.
-
Select the first cell in the current row.
- From the Actions panel, find and add action after the If action but within the Loop action.
- In Cell option, click Active cell and then select Beginning of the row.
- In Session name, enter Default.
- Save changes.
-
Select the next row before the next iteration.
- From the Actions panel, find and add action within the Loop action.
- In Cell option, click Active cell and then select One cell below.
- In Session name, enter Default.
- Save changes.
-
Close the current spreadsheet.
- From the Actions panel, find and add action after the Loop action.
- Select Save the changes when closing the file.
- In Session name, enter Default.
- Save changes.