Question of the Week at www.joecolantonio.com
Today's Question of the Week comes from my blog friend Irfan who asks “Is there any way to put auto generated date field? For example, I want the code to retrieve current system date and then add 20 days for check date. I just want to know how to add this kind of code.“
First – thanks for the question, Irfan, and I'm glad you like my site! There are two ways I can think of that will get the date functionality you need:
- The first method uses custom code.
- The second method can be done using Service Test 11.20 built in Date/Time activities.
How to Increment a Date using Custom Code
- In Service Test, drag a custom code activity to the main canvas area.
- Under the Custom Code properties section, select Events, and for the ExecuteEvent select “create a default handler.”
- Under the CodeActivity_OnexecuteEvent add the following lines of code:
DateTime today = DateTime.Now;
DateTime futureDate = today.AddDays(20);
- Run the test. A message box should appear with the correct future date.
How to Increment a Date using Service Test's built-in Date/Time activities
- In Service Test, click on the Date/Time folder under the Toolbox.
- Drag an Increment Date/Time to the main canvas.
- Drag a Form Date/Time to the main canvas.
- Click on the Increment Date/Time properties and click on the Original Date/Time “link to data source.”
- In the Select Link Source dialogue box, click on Test variables and select the CurrentDate system variable.
- Change the Units property to Days.
- Change the Amount to 20.
- Click on the Format Date/Time and set the following properties:
- Input Date/Time = link to the Increment Date/Time ‘Result.'
- Format = mm/dd/yyyy
- Run the test. The future date should appear in the output section:
Want your question answered in a post?
Would you like your question to be answered as a post on joecolantonio.com? Well, it's easy. All you have to do is e-mail me your question, or add a comment to an existing post. At the end of each week I'll select the best question and answer it in a post. Cool!