How to hide 'Close task' UI action on SC tasks when state is changed to closed rejected

sath
Tera Expert

Hi,

When an user sets the state to closed rejected on first catalog task, an alert will be triggered asking them to click on save button instead of close task button(it sets the state to closed complete). Still some users are clicking on close task button after setting the state to closed rejected and the state is getting closed complete instead of closed rejected.

So, we have decided to hide 'close task' UI action on first catalog task. I have created a UI policy with the below condition and selected isolate script to false.

function onCondition() {
$$('#close_sc_task')[0].hide();
}

It's working as per the requirement, but previewing the reference records from SC task form (like request item, requested for, item) is not working.

I have tried inserting the condition within UI action condition field, but it works only during onLoad. I need this functionality to work during onChange. Please assist.

1 ACCEPTED SOLUTION

Hi @sath ,

 

I am not sure what logic you are applying to check whether that's a first task or not. I applied my own logic to determine it, if it is the first one to be closed and all the remaining SC Tasks of that Requested Item are in the open state then I am considering it as an open Task.

 

In order to achieve this I am using a Display Business Rule and declared a scratchpad variable. Please find the code below.

 

Display BR Code:-

 

(function executeRule(current, previous /*null when async*/) {
// Add your code here
var notFirst;
var scTaskRec = new GlideRecord('sc_task');
scTaskRec.addQuery('request_item',current.request_item);
scTaskRec.query();
while(scTaskRec.next())
{
if(scTaskRec.state == '3' || scTaskRec.state == '4' || scTaskRec.state == '7') // if any sc task is closed
{
notFirst = 'yes';
}
}
if(notFirst == 'yes')
{
g_scratchpad.FirstTask = 'no';
}
else
{
g_scratchpad.FirstTask = 'yes';
}
})(current, previous);
MallidiSuma_0-1684256994693.png

 

 
Close Task UI action Code:-
function closeTask() {
    var state_val = g_form.getValue('state');
 
    if (state_val == '4' && g_scratchpad.FirstTask == 'yes') { // 4 is the backend value of Closed Incomplete
        alert("check the state");
    }
 
else {
        g_form.setValue('state', 3);
        //Call the UI Action and skip the 'onclick' function
        gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
    }
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    updateTask();
 
function updateTask() {
    current.state = 3;
    current.update();
}
 
In short, you can achieve this by using Display Business Rule.
 
Please mark my answer as helpful,  if it helps!!
 
Thanks & Regards,
Suma.
 

 

 

View solution in original post

14 REPLIES 14

Mallidi Suma
Tera Guru

Hi @sath ,

 

Write the below code in the "Close Task" UI action as per the screenshot.

 

Code:- 

function closeTask(){
var state_val = g_form.getValue('state');
if(state_val != '4') // Instead of 4 use the backend value of Closed Rejected.
{
g_form.setValue('state', 3);
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
}
else{
alert("check the state"); // Write your own alert message
}
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
   updateTask();
 
function updateTask(){
current.state = 3;
current.update();
}
MallidiSuma_0-1684249769382.png

 

Please mark my answer as helpful and a solution if it helps!!

 

Thanks & Regards,

Suma.

 

Hi @Mallidi Suma , Close task UI action should be hidden only for first catalog task, it should be visible for second, third and so no catalog tasks. The above script will hide UI action for all the catalog tasks. I have a script include and a client script to check if its the first catalog task and then set a checkbox to true accordingly. How do i leverage this in UI action?

Hi @sath ,

 

I am not sure what logic you are applying to check whether that's a first task or not. I applied my own logic to determine it, if it is the first one to be closed and all the remaining SC Tasks of that Requested Item are in the open state then I am considering it as an open Task.

 

In order to achieve this I am using a Display Business Rule and declared a scratchpad variable. Please find the code below.

 

Display BR Code:-

 

(function executeRule(current, previous /*null when async*/) {
// Add your code here
var notFirst;
var scTaskRec = new GlideRecord('sc_task');
scTaskRec.addQuery('request_item',current.request_item);
scTaskRec.query();
while(scTaskRec.next())
{
if(scTaskRec.state == '3' || scTaskRec.state == '4' || scTaskRec.state == '7') // if any sc task is closed
{
notFirst = 'yes';
}
}
if(notFirst == 'yes')
{
g_scratchpad.FirstTask = 'no';
}
else
{
g_scratchpad.FirstTask = 'yes';
}
})(current, previous);
MallidiSuma_0-1684256994693.png

 

 
Close Task UI action Code:-
function closeTask() {
    var state_val = g_form.getValue('state');
 
    if (state_val == '4' && g_scratchpad.FirstTask == 'yes') { // 4 is the backend value of Closed Incomplete
        alert("check the state");
    }
 
else {
        g_form.setValue('state', 3);
        //Call the UI Action and skip the 'onclick' function
        gsftSubmit(null, g_form.getFormElement(), 'close_sc_task');
    }
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
    updateTask();
 
function updateTask() {
    current.state = 3;
    current.update();
}
 
In short, you can achieve this by using Display Business Rule.
 
Please mark my answer as helpful,  if it helps!!
 
Thanks & Regards,
Suma.
 

 

 

Appreciate your response @Mallidi Suma . I have the logic already determined to check if its the first catalog task. I have created a check box and if its first catalog task, I'm checking the checkbox to true. I need to hide 'Close Task' UI action when user sets state to 'closed rejected'. How do I achieve this? The above code is checking if its first task and triggering the alert. But I need to hide 'Close Task' UI action only for the first catalog task.