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'
});
2 REPLIES 2

Ankith Sharma
Giga Guru

Hi @UtsabGiri 


You’re not missing a query instead this is framework behaviour .

 

In Project Workspace status reports, the entity key (risk_baseline) drives the data path, not the sourceTable defined in the schema. As long as the key is risk_baseline, the engine assumes a baseline exists and keeps resolving data through baseline logic, even if you point it to the risk table.

That’s why overriding _fetchDataFromBaselines() alone doesn’t work.

Try this method once

Explicitly tell the framework that this entity has no baseline:

 

_hasBaselineTable: function(entity) {
if (entity === 'risk_baseline') {
return false; // force source table usage
} return this._super(entity);
}
 
Keep your existing _fetchLiveRisks() logic as it is. Once baseline resolution is disabled, the framework will correctly fetch data from the risk table instead of risk_baseline.

 

If you found this useful, please mark it as Helpful and Accepted. This action benefits both the community and me.
Regards, 
- Ankit
LinkedIn: https://www.linkedin.com/in/sharmaankith/

Vincent_Shaw
Tera Contributor

The issue is that the engine still treats **`risk_baseline` as a baseline entity**, so baseline logic overrides your fetch.
You can’t reliably force it to use the `risk` table.
**Fix:** define a new entity (e.g. `risk_live`) pointing to the `risk` table and fetch data for that entity instead.