How to hide state pending in RITM

Sriram Pusuluri
Tera Contributor

Hi Team,

 

I have equirment, when sc_task state is pending and Pending Reason is Awaiting caller, Then I need set RITM state is Pedning.

 

It is working as expected, I have written Business Rule.

 

Now in RITM I need to hide state pending, means we pending need to select only from sc_task, Not manually, for this reason I need to hide that or disable, But It should show when all sc_task is pending and Pending reason is Awaiting caller, in this case it should show 

1 REPLY 1

Tanushree Maiti
Giga Patron

Hi @Sriram Pusuluri 

 

Try this:

 

 

  1. create onload client script  to remove the Pending option from the choice list by default

 

function onLoad() {

     g_form.removeOption('state', '3'); //  assuming 3 - pending

    var ritmSysId = g_form.getUniqueValue();

    var ga = new GlideAjax('RITMStateUtils');

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

    ga.addParam('sysparm_ritm_id', ritmSysId);

    ga.getXMLAnswer(function(answer) {

        if (answer == 'true') {

            g_form.addOption('state', '3', 'Pending');

        }

    });

}

 

  1. create Script include to check the tasks related to the RITM

 

var RITMStateUtils = Class.create();

RITMStateUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkScTaskPendingState: function() {

        var ritmSysId = this.getParameter('sysparm_ritm_sys_id');

        var taskGr = new GlideRecord('sc_task');

        taskGr.addQuery('request_item', ritmSysId);

        taskGr.query();

        var totalTasks = taskGr.getRowCount();

        var pendingScTasks = 0;

         while (taskGr.next()) {

             if (taskGr.state == 3 && taskGr.pending_reason == 'awaiting_caller') {

                pendingTasks++;

            }

        }

        if (totalTasks > 0 && totalTasks === pendingTasks) {

            return 'true';

        }       

        return 'false';

    },

    type: 'RITMStateUtils'

});

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: