ATF - How access hamburger options or templates in automated test framework?

ruthmosman
Kilo Contributor

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.

find_real_file.png

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!

1 ACCEPTED SOLUTION

1. Go to 'Step Configurations'. New. Fill out the form as follows:


find_real_file.png



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:


find_real_file.png



find_real_file.png



4. Add Output Variables on the Step Configuration form:


find_real_file.png



5. Test it.



Let me know if you have any questions.


View solution in original post

14 REPLIES 14

ruthmosman
Kilo Contributor

Hi, Masha.



I'm (finally) getting around to trying to implement your solution and am bumping into errors when trying to add the u_template input variable in both Istanbul and Jakarta.



In Istanbul, the operation was aborted by a business rule "Validate Reference Field." Did you bump into anything like that?



In Jakarta, I didn't see that error but in both platforms it did tell me it was invalid and threw an error of "Select a Reference for the reference type field u_template." I can't save the input so that I can edit it to have the info in your "Reference Specification" tab.



If you have some special way of getting that value in there or tips on how best to resolve the error I'm seeing, I would appreciate it.



Thanks so much!



Ruth


Could you, please,   provide a screen shot of the error and your u_template input variable form to help me understand what you are describing?



Thanks


ruthmosman
Kilo Contributor

Hi, Masha.



I worked with my ServiceNow rep and was able to resolve the blocking issue. I couldn't see the tabs that are in your screen shot in step 3, so I couldn't set the fields in the "Reference Tab." It would seem that it is a Jakarta defect so he's having me open a ticket with HI on it.



Bottom line: I have been able to implement your solution and it works!!!



Thank you so so much for your help. It is much appreciated!



~ Ruth


Great! I am glad it worked out for you. ruthmosman, could you possibly share the steps SN had you take in order to correct the issue? I am not having to deal with it as well in Jakarta



Thank you!


ruthmosman
Kilo Contributor

Hi, Masha.



We configured the "Input Variables Form" -- added the key fields to set onto the main form rather than having them be in the conditional tabs. That worked well as a workaround.



Thanks.



~ Ruth