Issue with Conditional Display of PIR Section in Change Request

suvarnamoha
Tera Contributor

In the Change Request form, we are trying to conditionally display the Post Implementation Review (PIR) tab only when a related Change Task of type 'Review' exists.

To achieve this, I created a client Script that calls a Script Include via Glide Ajax. The response from the Script Include is working as expected — it returns true when a Review task exists and false otherwise.

However, the issue is that the PIR section is displaying all the time, regardless of the response. 

Here’s a summary of what I’ve done:

  • Script Include is client-callable and functioning correctly.
  • Client Script receives the correct response.
  • There are no UI Policies forcing the section to display.

Despite this, the section remains visible even when the response is false

Can anyone help identify why the section is not hiding and suggest an alternative solution?

 

Client Script:

function onLoad() {

    var ga = new GlideAjax('CheckReviewTaskExists');

    ga.addParam('sysparm_name', 'reviewTaskExists');

    ga.addParam('sysparm_change_id', g_form.getUniqueValue());

    ga.getXMLAnswer(function(response) {

               if (response === 'true') {

              g_form.setSectionDisplay("post_implementationreview", true);

        } else {

                g_form.setSectionDisplay("post_implementationreview", false);

        }

    });

}

 

Script include: 

var CheckReviewTaskExists = Class.create();

CheckReviewTaskExists.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    reviewTaskExists: function () {

           var changeRequestId = this.getParameter('sysparm_change_id');

          var gr = new GlideRecord('change_task');

        gr.addQuery('change_request', changeRequestId);

        gr.addQuery('change_task_type', 'review');

        gr.query();

   if(gr.hasNext()){

return true;

}

else {

return false;

}

            }

});

 

Thank you in Advance.

1 REPLY 1

Roshan Tiwari
Tera Guru

Please try below client script and Script Include:

 

function onLoad() {

    var ga = new GlideAjax('CheckReviewTaskExists');

    ga.addParam('sysparm_name', 'reviewTaskExists');

    ga.addParam('sysparm_change_id', g_form.getUniqueValue());

    ga.getXMLAnswer(function(response) {

               if (response == 'true') {

              g_form.setSectionDisplay("post_implementationreview", true);

        } else {

                g_form.setSectionDisplay("post_implementationreview", false);

        }

    });

}

 

 

Script include: 

var CheckReviewTaskExists = Class.create();

CheckReviewTaskExists.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    reviewTaskExists: function () {

           var changeRequestId = this.getParameter('sysparm_change_id');

          var gr = new GlideRecord('change_task');

        gr.addQuery('change_request', changeRequestId);

        gr.addQuery('change_task_type', 'review');

        gr.query();

   if(gr.hasNext()){

return "true";

}

else {

return "false";

}

            }

});