Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

In project status report, I want to show risks from the source table instead of risk_baseline table

UtsabGiri
Tera Expert

I have created a custom report template to extract project status report in PDF from reports tab of the Project Workspace. Here, I have extended the script include "StatusReportDynamicTemplateSchemaSNC" function "

dynamicTemplateSchemaTableConfig". This allows me to choose fields from the 'risk' table as dynamic content.
risk_baseline: {
                sourecTable: "risk",
                baselineTable: "", 
                encodedQuery: "active=true^taskISNOTEMPTY",  
                baselineTableEncodedQuery: "",
                orderBy: "number",
                label: gs.getMessage('Risk')
            },

Then I have extended the script include "StatusReportDynamicTemplateDataProvider" function "

_fetchDataFromBaselines" and subsequent related functions but unable to fetch data from the source table "risk" instead of "risk_baseline". below is the code. 
Could anyone help what I am missing out here?
var StatusReportDynamicTemplateDataProvider = Class.create();
StatusReportDynamicTemplateDataProvider.prototype = Object.extendsObject(sn_pw.StatusReportDynamicTemplateDataProviderSNC, {

    _fetchDataFromBaselines: function(entity, fieldNames, reportRecord) {

        // === RISKS: Force live table instead of baseline ===

        if (entity === 'risk_baseline') {
            return this._fetchLiveRisks(fieldNames, reportRecord);
        }

        // All other entities (issues, decisions, milestones, etc.) → keep OOB behavior

        return this._super(entity, fieldNames, reportRecord);
    },

    _fetchDataFromSourceTables: function(entity, fieldNames, reportRecord) {

        // === RISKS: Also force live table when no baseline exists ===

        if (entity === 'risk_baseline') {
            return this._fetchLiveRisks(fieldNames, reportRecord);
        }

        return this._super(entity, fieldNames, reportRecord);
    },

    _fetchLiveRisks: function(fieldNames, reportRecord) {
        var projectId = reportRecord.getValue('project');
        if (!projectId) {
            return [];
        }

        var queryObj = {
            task: projectId,
            active: true
        };

        var testGr = new GlideRecord('risk');
        if (testGr.isValidField('show_on_status_report')) {
            queryObj.show_on_status_report = true;
        }

        var schema = new sn_pw.StatusReportDynamicTemplateSchema();
        var config = schema.dynamicTemplateSchemaTableConfig();
        var riskConfig = config['risk_baseline'];    // key stays 'risk_baseline'

        // Force table to 'risk' and use correct query
        return this._fetchRecords('risk', queryObj, fieldNames, riskConfig);
    },

    _fetchRecords: function(tableName, queryObj, fieldNames, entitySchemaConfig) {
        var encodedQuery;

        // If baselineTable is empty or doesn't match → use live table query

        if (!entitySchemaConfig.baselineTable || tableName !== entitySchemaConfig.baselineTable) {
            encodedQuery = entitySchemaConfig.encodedQuery || '';
        } else {
            encodedQuery = entitySchemaConfig.baselineTableEncodedQuery || '';
        }

        var orderBy = entitySchemaConfig.orderBy || 'sys_created_on';

        var gr = this._queryGlideRecord(tableName, queryObj, orderBy, encodedQuery);
        return this._createRecordObjects(gr, fieldNames, tableName);
    },
    type: 'StatusReportDynamicTemplateDataProvider'
});
0 REPLIES 0