To close all tasks before closing requested item

moulik1
Kilo Guru

Hello All,

we have a scenario where user should not be able to close requested item until and unless all the tasks related to that requested item are closed,

for the same there is a before update business rule as below.

var rec = new GlideRecord('sc_task');

rec.addQuery('request_item',current.sys_id);

rec.addQuery('state','!=',3);

rec.query();

if(rec.next())

{

gs.addErrorMessage('Please close all the tasks before closing the requested item');

current.setAbortAction(true);

There is client script when status is closed all the fields will be made read only.

So the issue here is when user changes the status to close in requested item and updates it , it gives invalid update based on the above BR, and all the fields are greyed out because of the client script,

But actually the transaction is not complete (i.e. the requested item is still open), which user comes to know when he reloads or refresh the form which is actually mis-leading.

please let me know what are the modifications to be done.

Thanks

1 ACCEPTED SOLUTION

It seems like setAbortAction is not working . Following   thread may help you a little



setAbortAction not firing


View solution in original post

11 REPLIES 11

Gurpreet07
Mega Sage

I believe that you are using a onChange client script on state field , use onload Client Script instead to make fields readonly.


I changed it to Onload but that didn't help.


Look .. if you moved the code to onLoad   then fields will not become readOnly after changing the state but they will become readOnly after you save those changes and page is reloaded.   Now ,   at onLoad if the update operation was successful then only the state will be closed and thus all fields will be readOnly else not.




Can you share the code of onLoad Script.


The code onLoad looks like this.


function onLoad() {


    //Type appropriate comment here, and begin script below


  if(g_form.getValue('state') == 3)


    {


    var fields = g_form.getEditableFields();


for (var x = 0; x < fields.length; x++)


{


g_form.setReadOnly(fields[x],true);


}


    }


    }