[BCM] Amending Dependency section within BIA PDF Template

Mickey Goldstei
Tera Contributor

Hello,

 

I've created additional columns within the Dependencies section for a few elements using the Grid Configuration method. 

 

However, when I generate a PDF of a BIA, these columns are not appearing (only the default ones are). 

 

How do I amend the script for fetching Dependency data within the PDF template [ ${template_script:getDependencySectionForBIA} ] in a way so that it can include the custom columns that I've created?

 

MickeyGoldstei_0-1690575888017.png

cc: @Connor Levien 

 

Regards,

Mickey

1 ACCEPTED SOLUTION

Connor Levien
ServiceNow Employee
ServiceNow Employee

hey @Mickey Goldstei,

 

Sorry for the delay responding its been a hectic week! You need to go to the "sn_doc_template_script" table (Document Template > Document Template Script in nav) and I would suggest copying the getDependencySectionForBIA script and making your own version. Using your new version you would have to modify the below glide record to look up the database view you made in the other question you raised to get the grid configuration variables

 

 

var biaDependenciesForGroup = new GlideRecord('sn_bia_dependency');

 

 

You would then need to update the below part of the script to add addition <th> elements and addition td element for you corresponding new fields from the database view.

 

if (biaDependenciesForGroup.hasNext()) {
    tableBodyContent = '<tr>' +
        '<th width="60%">' + 'Depends On' + '</th>' +
        '<th width="20%">' + 'RRTO' + '</th>' +
        '<th width="20%">' + 'RRPO' + '</th>' +
        '</tr>';
    while (biaDependenciesForGroup.next()) {
        tableBodyContent = tableBodyContent +
            '<td width="60%">' + biaDependenciesForGroup.getDisplayValue('depends_on') + '</td>' +
            '<td width="20%">' + biaDependenciesForGroup.getDisplayValue('required_recovery_timeframe') + '</td>' +
            '<td width="20%">' + biaDependenciesForGroup.getDisplayValue('required_data_backup') + '</td>' +
            '</tr>';

    }
    tableBody = '<tbody>' + tableBodyContent + '</tbody> <br/>';
    resultTable += tableOpenTag + tableBody + tableCloseTag + '<br/>';
}

 

 

Finally you would just have to update the below in the document template to whatever your new script is called.

 

[ ${template_script:getDependencySectionForBIA} ]

 

 

Let me know if that helps.

View solution in original post

4 REPLIES 4

Karin4
ServiceNow Employee
ServiceNow Employee

From the script, edit to include the custom columns you created in the Dependencies section. You will probably need to use GlideRecord queries to access the custom columns within the Dependencies section. These columns are most likely stored in a separate table or fields. Next, you'll need to incorporate it into the PDF template's script.

 

Hope this helps.

Connor Levien
ServiceNow Employee
ServiceNow Employee

hey @Mickey Goldstei,

 

Sorry for the delay responding its been a hectic week! You need to go to the "sn_doc_template_script" table (Document Template > Document Template Script in nav) and I would suggest copying the getDependencySectionForBIA script and making your own version. Using your new version you would have to modify the below glide record to look up the database view you made in the other question you raised to get the grid configuration variables

 

 

var biaDependenciesForGroup = new GlideRecord('sn_bia_dependency');

 

 

You would then need to update the below part of the script to add addition <th> elements and addition td element for you corresponding new fields from the database view.

 

if (biaDependenciesForGroup.hasNext()) {
    tableBodyContent = '<tr>' +
        '<th width="60%">' + 'Depends On' + '</th>' +
        '<th width="20%">' + 'RRTO' + '</th>' +
        '<th width="20%">' + 'RRPO' + '</th>' +
        '</tr>';
    while (biaDependenciesForGroup.next()) {
        tableBodyContent = tableBodyContent +
            '<td width="60%">' + biaDependenciesForGroup.getDisplayValue('depends_on') + '</td>' +
            '<td width="20%">' + biaDependenciesForGroup.getDisplayValue('required_recovery_timeframe') + '</td>' +
            '<td width="20%">' + biaDependenciesForGroup.getDisplayValue('required_data_backup') + '</td>' +
            '</tr>';

    }
    tableBody = '<tbody>' + tableBodyContent + '</tbody> <br/>';
    resultTable += tableOpenTag + tableBody + tableCloseTag + '<br/>';
}

 

 

Finally you would just have to update the below in the document template to whatever your new script is called.

 

[ ${template_script:getDependencySectionForBIA} ]

 

 

Let me know if that helps.

Hello Connor,

 

Apologies for the late reply.

 

I've been toying with this, and I am able to get it work with a few other changes!


Upon running the script, I have the following output:

MickeyGoldstei_1-1692996132389.png

Relevant code:

 if (biaDependenciesForGroup.hasNext()) {
            tableBodyContent = '<tr>' +
                '<th width="60%">' + 'Depends On' + '</th>' +
                '<th>' + 'RRTO' + '</th>' +
                '<th>' + 'RRPO' + '</th>' +
                '</tr>';
            while (biaDependenciesForGroup.next()) {
                tableBodyContent = tableBodyContent +
                    '<td width="60%">' + biaDependenciesForGroup.getDisplayValue('dep_depends_on') + '</td>' +
                    '<td>' + biaDependenciesForGroup.getDisplayValue('var_variable') + '</td>' +
                    '<td>' + biaDependenciesForGroup.getDisplayValue('var_value') + '</td>' +
                    '</tr>';

            }

Is there a solution where I can have var_variable values act as columns, and the var_value values be nestled in as values under those columns?

 

Ideally I'd want it to look something like this:

Depends OnContingency StrategyDescription of Contingency Strategy
Software: Musicmatch® Jukebox 9.0.2028Manual WorkaroundTest

 

 

Thanks!

Mickey

 

Hey Mickey,

 

Glad to see you were able to have a go at it. You can definitely achieve what you want to but because the way your biaDependenciesForGroup is set up its returning each variable as its own row and thats why you are getting the repeates. You will need to either update the logic of the function to group or you will need to in your script remember what "depends on" you are looking at as part of the while loop so you can merge the rows.

 

Below is an example of how you may tackle it using your script as a basis. Please not I havent tested this and no guarantee it works but its just to illustrate how it could be done.

if (biaDependenciesForGroup.hasNext()) {
    tableBodyContent = '<tr>' +
        '<th width="60%">' + 'Depends On' + '</th>' +
        '<th>' + 'Contingency Strategy' + '</th>' +
        '<th>' + 'Description of Contingency Strategy' + '</th>' +
        '</tr>';

    var currentDepends = '';
    var contingencyStrategy = '';
    var contingencyDescription = '';
    while (biaDependenciesForGroup.next()) {
        if (currentDepends == '') {
            currentDepends = biaDependenciesForGroup.getDisplayValue('dep_depends_on');
        }
        if (currentDepends == biaDependenciesForGroup.getDisplayValue('dep_depends_on')) {
            if (biaDependenciesForGroup.getDisplayValue('var_variable') = 'Contingent Strategy') {
                contingencyStrategy = biaDependenciesForGroup.getDisplayValue('var_value');
            }
            if (biaDependenciesForGroup.getDisplayValue('var_variable') = 'Description of Contingency Strategy') {
                contingencyDescription = biaDependenciesForGroup.getDisplayValue('var_value');
            }
        } else {
            tableBodyContent = tableBodyContent +
                '<td width="60%">' + currentDepends + '</td>' +
                '<td>' + contingencyStrategy + '</td>' +
                '<td>' + contingencyDescription + '</td>' +
                '</tr>';

            currentDepends = biaDependenciesForGroup.getDisplayValue('dep_depends_on');

            if (biaDependenciesForGroup.getDisplayValue('var_variable') = 'Contingent Strategy') {
                contingencyStrategy = biaDependenciesForGroup.getDisplayValue('var_value');
            }
            if (biaDependenciesForGroup.getDisplayValue('var_variable') = 'Description of Contingency Strategy') {
                contingencyDescription = biaDependenciesForGroup.getDisplayValue('var_value');
            }
        }
    }
}