ATF - Custom Step Configuration1 - Get Display value of a Field
ATF - Custom Step Configuration - Get Display value of a Field
Hi,
As part of my ATF test development, I ran into cases where I need the display value of certain fields in the record generated. I have created an Custom step - server independent that retrieves the display of a field and passes to output variable.
Here is the information on creating this step configuration:
Step Environment: Server Independent
Category: Server
Input Variables:
- Input String: Column Name = u_tablename, Type = String
- Input String: Column Name = u_sysid, Type = String
- Input String: Column Name = u_fieldname, Type = String
Output Variables:
- Output String: Column Name = u_displayvalue, Type = String
Description Script:
function generateDescription(step) { // the global variable 'step' represents the current glide record var description = gs.getMessage("Retrieves the display value of field : '{0}'", step.inputs.u_fieldname); return description;}
generateDescription(step);
Step execution script:
(function executeStep(inputs, outputs, stepResult, timeout) { var tableName = inputs.u_tablename; var sysId = inputs.u_sysid; var fieldName = inputs.u_fieldname; var rowCount;
var displayName;
var MESSAGE_KEY_NO_DISPLAY_VALUE = "Failure: Display name cannot be retrieved, either the Tablename/FieldName are not correct or Field does not have any value";
var MESSAGE_KEY_SUCCESS = "Success: Display value of the field " + fieldName +" is passed to the output variable";
function logic() {
var gr = new GlideRecord(tableName); gr.addQuery('sys_id', sysId); gr.query(); rowCount = gr.getRowCount(); while(gr.next()){ displayName = gr.getDisplayValue(fieldName); }
}
function passStep() { outputs.u_displayvalue = displayName; stepResult.setOutputMessage(MESSAGE_KEY_SUCCESS);
stepResult.setSuccess();
}
function failStep() { stepResult.setOutputMessage(MESSAGE_KEY_NO_DISPLAY_VALUE);
stepResult.setFailed();
} logic(); if (rowCount >= 1 && displayName !== null) { passStep(); } else { failStep(); }
}(inputs, outputs, stepResult, timeout));
Labels:
https://www.servicenow.com/community/developer-articles/atf-custom-step-configuration1-get-display-value-of-a-field/ta-p/2315648
