Action Output: Display Values: Empty output value cannot be blank on publish.

marcmcfry
Mega Contributor

Hello, I need help. I would appreciate any help you can give me. I am trying have sysid readable format in a HTML email. Thanks

Script:

(function execute(inputs, outputs) {
    // Default output value
    outputs.display_values = 'No values selected';

    var listCollectorField = inputs.list_collector_field; // List Collector sys_ids
    var tableName = inputs.table_name; // Target table name

    // Proceed only if the input field has values
    if (listCollectorField && tableName) {
        var displayValues = []; // Array to hold resolved values

        try {
            var sysIdArray = listCollectorField.split(','); // Split sys_ids into an array

            // Query the table to retrieve the fields
            var gr = new GlideRecord(tableName);
            for (var i = 0; i < sysIdArray.length; i++) {
                if (gr.get(sysIdArray[i])) {
                    var application = gr.getValue('application') || 'N/A';
                    var businessApplication = gr.getValue('business_application') || 'N/A';

                    // Format as "Application: value, Business Application: value"
                    var formattedValue = 'Application: ' + application + ', Business Application: ' + businessApplication;
                    displayValues.push(formattedValue);
                }
            }

            // Update the output if display values are found
            if (displayValues.length > 0) {
                outputs.display_values = displayValues.join('<br>'); // HTML-friendly line breaks
            }
        } catch (e) {
            // Catch errors and set an error message
            gs.error('Error in Script Step: ' + e.message);
            outputs.display_values = 'Error fetching values';
        }
    }
})(inputs, outputs);
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@marcmcfry 

what's the issue? what debugging have you done so far?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@marcmcfry 

did you print in log what came in the array?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader