- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 09:24 AM
Does anyone have input as to how to use the ATF for applying templates to a form?
Manual action requires that the user click on the hamburger and from the options selects "Templates" and then "Apply Template" and then selecting the specific template.
I'm looking to write automated tests that use templates for testing different forms and application areas (screenshot above is for Project) and need help to know how to apply templates to an automated test.
Has anyone tried this or know if this is functionality is available and I'm just missing it, or if it is absent, when it might be available?
Thanks in advance for the input!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:04 PM
1. Go to 'Step Configurations'. New. Fill out the form as follows:
Description generation script:
(function generateDescription(step) {
var descriptionGenerator = new ATFStepDescriptionGenerator();
var description = gs.getMessage("Insert a record into '{0}' and apply template", step.inputs.u_table);
description += descriptionGenerator.getConditionDescription(step.inputs.u_table);
return description;
})(step);
Step execution script:
(function executeStep(inputs, outputs, stepResult) {
//check template and get template name
var template_name = '-';
var t = new GlideRecord('sys_template');
if(t.get(inputs.u_template)){
template_name=t.name;
//check if template exists for the selected table
if(t.table != inputs.u_table){
stepResult.setOutputMessage("Template: "+template_name+" doesn't exist for this table: "+inputs.u_table);
stepResult.setFailed();
}
else{
//Create record and apply template.
var inc = new GlideRecord(inputs.u_table);
inc.initialize();
inc.applyTemplate(template_name);
var id = inc.insert();
outputs.u_record_id = id;
stepResult.setOutputMessage("Record Created: "+id);
stepResult.setSuccess();
}
}
else{
stepResult.setOutputMessage("Could not find name of the template with sys_id: "+inputs.u_template);
stepResult.setFailed();
}
}(inputs, outputs, stepResult));
2. Save.
3. Add Input Variables on the Step Configuration form:
4. Add Output Variables on the Step Configuration form:
5. Test it.
Let me know if you have any questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 02:48 PM
I don't believe this functionality is currently available. I have gotten around this issue by creating a reusable custom Test Step Config that creates a record on a given table and applies the selected template. Let me know if you are still working on this and I will share my code with you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 02:55 PM
I've been blocked on this so anything that you can share would be much appreciated! Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2017 04:04 PM
1. Go to 'Step Configurations'. New. Fill out the form as follows:
Description generation script:
(function generateDescription(step) {
var descriptionGenerator = new ATFStepDescriptionGenerator();
var description = gs.getMessage("Insert a record into '{0}' and apply template", step.inputs.u_table);
description += descriptionGenerator.getConditionDescription(step.inputs.u_table);
return description;
})(step);
Step execution script:
(function executeStep(inputs, outputs, stepResult) {
//check template and get template name
var template_name = '-';
var t = new GlideRecord('sys_template');
if(t.get(inputs.u_template)){
template_name=t.name;
//check if template exists for the selected table
if(t.table != inputs.u_table){
stepResult.setOutputMessage("Template: "+template_name+" doesn't exist for this table: "+inputs.u_table);
stepResult.setFailed();
}
else{
//Create record and apply template.
var inc = new GlideRecord(inputs.u_table);
inc.initialize();
inc.applyTemplate(template_name);
var id = inc.insert();
outputs.u_record_id = id;
stepResult.setOutputMessage("Record Created: "+id);
stepResult.setSuccess();
}
}
else{
stepResult.setOutputMessage("Could not find name of the template with sys_id: "+inputs.u_template);
stepResult.setFailed();
}
}(inputs, outputs, stepResult));
2. Save.
3. Add Input Variables on the Step Configuration form:
4. Add Output Variables on the Step Configuration form:
5. Test it.
Let me know if you have any questions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 06:46 AM
Thank you so much for sharing! Much appreciated!!!!!
~ Ruth