UI action

BhupathiC
Tera Contributor

Hello all,

 

I have created a Cancel UI action button on the form,

 

i) this button should be visible only when all the related tasks of that particular record are closed, if any one task      record is in open state then the button should not be visible and

ii) once the record is Cancelled the Cancel UI action button should not be visible.

 

 

I attached the screenshot of the code which i wrote , suggest with best methods

3 REPLIES 3

GlideFather
Tera Patron

Hi @BhupathiC,

 

the view conditions are set out of the script field, can you share that as well?

and also, what's the current behaviour? is the button displayed always or never....?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Bhimashankar H
Mega Sage

Hi @BhupathiC ,

 

This is best done using the UI Action’s Condition field server-side.

 

There is condition field there you can enter below code snippet.

if (current.state == 'Cancelled') {
    answer = false;
    return;
}

var taskGR = new GlideRecord('change_task');
taskGR.addQuery('change_request', current.sys_id);
taskGR.addQuery('state', '!=', 3); // Assuming '3' is Closed
taskGR.query();

answer = !taskGR.hasNext(); // Show if no open tasks

 

Try it out!

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Bhimashankar H
Mega Sage

Hey @BhupathiC ,

 

I hope you saw my reply. 

 

Did you get chance to try it out. If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. It will help future readers as well having similar kind of questions and close the thread.

Thanks,
Bhimashankar H