show/hide form section on change request form if the caused by change field on incident is populated

Jason Biden
Tera Contributor

Hi All,

 

I hope you are well, I am new to scripting in SNOW and have a interesting use case. The Change Management team run post implementation reviews on changes that cause incident(s). please keep in mind im doing all of this in a PDI.

 

what we have is:

a "failed change review" section on the change_request form with custom fields and related lists (screenshot below) 

JasonBiden_0-1721371896253.png

 

what is needed is:

when the "caused by change" field on the INCIDENT form is initially set or updated, look up field and show the "failed change review" section on the corresponding change_request form but if the caused by change field is empty then dont show "failed change review" tab on change request form,

 

Example:

ie. if CHG0000030 caused 3 incidents the show the "failed change review" section on the change_request form if not then hide it.

 

 

JasonBiden_1-1721371896287.png

 

 

4 REPLIES 4

Mark Manders
Tera Patron

For one: if you are using SNOW, you are on the wrong community, because SNOW is a completely different platform than ServiceNow.

 

But since your question does look ServiceNow related: you can hide sections through client scripts (https://www.servicenow.com/community/now-platform-forum/show-hide-form-section-using-client-script/m...) or use a scripted ui policy.

 

Jason Biden
Tera Contributor

Hi Mark,

 

apologies please forgive my ignorance, yes my query is related to ServiceNow, specifically a client script to hide a form section based on value in another table, the info in the link partially answers my question, I just need to answer the part of how we lookup the "caused by incident" field on the incident form.

 

if this forum is not meant to be a technical forum for sys admins I will try find another forum to post on.

This should give you a start:

 

onLoad client script:

function onLoad() {

    function hideSectionIfCausedByChange() {
        var ga = new GlideAjax('IncidentCausedByChangeChecker');
        ga.addParam('sys_id', g_form.getUniqueValue()); 
        ga.getXMLAnswer(function(response) {
            var isCausedByChange = response.responseXML.documentElement.getAttribute("answer") === 'true';
            if (isCausedByChange) {
                g_form.setSectionDisplay('section_name', false); //replace with the name of the section you want to hide
            }
        });
    }
    
    hideSectionIfCausedByChange();
}

 

Client callable script include:

var IncidentCausedByChangeChecker = Class.create();
IncidentCausedByChangeChecker.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    isCausedByChange: function() {
        var changeId = this.getParameter('sys_id');
        var incidentGR = new GlideRecord('incident');
        incidentGR.addQuery('caused_by_change', changeId);
        incidentGR.query();
        if (incidentGR.next()) {
            return 'true';
        }
        return 'false';
    }
});

thanks heaps for your help Mark, I will give it a go.