Update State field on the Incident form from Read only to Read write

riskay123
Mega Guru

I am playing around with record producers for incidents created from the Service Portal using Flowdesigner for the workflow in my PDI. I have created a few flows for requests, and they are working well in our company instances. This is my first-time troubleshooting options for incidents. I have most of it worked out, but I have a question about the recommended approach for the below scenario.

 

The flow has two tasks that have the "Wait" box ticked so they run subsequently. This all works well.

 

I have added a client script on the catalogue item that makes the "State" field on the incident form read-only. This is to force the fulfiller to complete all the tasks related to the incident before the incidents can be closed to prevent orphaned tasks.

 

Question:  How can I make the State field change from Read Only to Read Write after the last task has been completed so the fulfiller can manually go and add the Resolution Notes and update the State field on the incident form? Is this the best way to handle this type of scenario or is there a better way to handle it? 

 

Thanks 🙂

 

 

 

 

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@riskay123 You can write a display business rule, in this business rule check if all the tasks related to parent incident have been completed, if the result is true, set the g_scratchpad variable to true. 

 

Here are the steps how you should configure it.

 

Screenshot 2024-01-14 at 5.45.14 PM.pngScreenshot 2024-01-14 at 5.45.45 PM.png

Here is the business rule script

(function executeRule(current, previous /*null when async*/ ) {

    g_scratchpad.checkAllTaskClosed = false;
    // Add your code here
    var incidentTask = new GlideRecord('incident_task');
    incidentTask.addQuery('incident', current.sys_id);
    incidentTask.query();
    var totalTaskCount = incidentTask.getRowCount();
    var taskClosedCount = 0;
    while (incidentTask.next()) {
        if (incidentTask.getValue('state') == '3') {
            taskClosedCount++;
        }
    }

    if (totalTaskCount == taskClosedCount) {
        g_scratchpad.checkAllTaskClosed = true;
    }


})(current, previous);

As a next step create an onLoad script on the incident form and check the value of scratchpad variable. Accordingly set the ReadOnly state of state field.

 

Screenshot 2024-01-14 at 5.53.44 PM.png

Here is the client script.

function onLoad() {
    //Type appropriate comment here, and begin script below
    if (g_scratchpad.checkAllTaskClosed == true) {
        g_form.setReadOnly('state', false);		
    } else {
        g_form.setReadOnly('state', true);		
    }

}

Hope this helps.

 

Hi Sandeep,

 

Thank you for your reply and for providing so much information. I have followed your suggested instructions and it is still not updating the state field to "Resolved" once all the tasks have been closed and the Resolution Information.

 

I am not a coder, but I am trying to make sense of it. I just copied and pasted your scripts without making any changes. Would it not be working because my catalog item only has 2 tasks and the script references "3"? I did try changing that to a "2" but it didn't make any difference. 

 

 while (incidentTask.next()) {
        if (incidentTask.getValue('state') == '3') {
            taskClosedCount++;

 

Below are screenshots from my PDI.

 

Screenshot 1.jpgScreenshot 2.pngScreenshot 3.png

 Do I need to add anything to the flow maybe?