- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 09-06-2020 04:50 PM
I've been creating ATF custom step configurations to make creating tests easier. One situation I ran encountered a few times was needing to get a user for a group. I created a custom step configuration that gets the user for a group and that user's manager, since I found I often needed the user's manager as well.
Here is the information for the test configuration:
Step Environment: Server Independent
Category: Server
Description Script:
function generateDescription() {
// the global variable 'step' represents the current glide record
var description = "";
// your code here
description = "Run the step using the following parameters.";
if (!gs.nil(step.inputs.u_group.getDisplayValue())) {
var text = step.inputs.u_group.getDisplayValue() + "";
description += "\n-- u_group: " + text.trim();
}
var outparams = "";
outparams += "\n--u_user = The user who is a member of the group";
outparams += "\n--u_manager = The user who is the manager of the user";
description += "\n\n The step outputs values in following output parameters\n";
description += outparams;
return description;
}
generateDescription();
Executing Script:
(function executeStep(inputs, outputs, stepResult, timeout) {
// Get the input parameters
var record = (!gs.nil(inputs.u_group)) ? inputs.u_group + "" : "";
// var table = (!gs.nil(inputs.u_table)) ? inputs.u_table + "" : "";
// add content to the message;
var message = "";
// set the "success" variable to false if there is an expected result in the script
var success = true;
var searchTable = "sys_user_group";
var grGroup = new GlideRecord(searchTable);
if (grGroup.get(record)) {
var grUgm = new GlideRecord("sys_user_grmember");
grUgm.addQuery("group", record);
grUgm.addQuery("user.active", true);
grUgm.addQuery("user.manager.active", true);
grUgm.query();
if (grUgm.next()) {
outputs.u_user = grUgm.getValue("user") + "";
outputs.u_manager = grUgm.user.manager.getValue() + "";
message += "\nUser " + grUgm.getValue("user") + "";
message += "\nManager " + grUgm.user.manager.getValue() + "";
message += "\n outputs.u_user " + outputs.u_user + "";
message += "\noutputs.u_manager " + outputs.u_manager + "";
} else {
success = false;
message += "\nCould not get the User for the group\nQuery = " + grUgm.getEncodedQuery();
}
} else {
success = false;
message += "\nCould not get the group record from the group ID\nQuery = " + grGroup.getEncodedQuery();
}
if (success) {
stepResult.setOutputMessage('Success!' + message);
stepResult.setSuccess();
} else {
stepResult.setOutputMessage('Failure!\n' + message);
stepResult.setFailed();
}
}(inputs, outputs, stepResult, timeout));
Input Variables
- Group: Type = Document ID, Column Name = u_group
Out put Variables
- User: Type = Document ID, Column Name = u_user
- Manager: Type = Document ID, Column Name = u_manager
I hope someone finds this useful.
Thanks,
Cody
- 1,920 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
Thanks for sharing this. I was able to create a Step Config (in Step Config Application is Global). It works great for Test Cases in Package Global. However for Test Cases in package "Human Resources Core" it does not work. So I recreated the Step Config with Application as "human resources core". The test step fails with error "ERROR Test failed: Function getValue is not allowed in scope sn_hr_core". Do you know a workaround for this ? Thanks.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Found the solution. Instead of getValue used ToString for the Step Config in the Scoped Application
outputs.u_user = grUgm.user.toString() + "";