Creat an UI action button that should check all the child tickets are closed before closing the parent

vijay23
Tera Contributor

Hi all,

I have an urgent requirement 

I have to create an UI action button name as 'close' on 'Issue table' that should be visible to only users having some role. when state is resolved in issue table. It should check that all the related "issue tasks"(child table of issue table) should be closed before closing the issues. If all the tasks are closed issues should also be closed. 

I tried the code below but it is not working as expected

Condition - gs.hasRole('issue_mgmt_worker')

code- 

var rec = new GlideRecord('u_issue_task');

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

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

rec.query();

if(rec.next()){

gs.addErrorMessage('All issue taks should be closed before resolving/closing issue ' + current.number + ' record'); // use valid number field

current.setAbortAction(true);

}
else
{
current.state='3';
current.update();
}
action.setRedirectURL(current);

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vijay,

Did you try adding logs to check till where it is working fine

Check is the number field a valid field?

Should it not be u_number since it is your custom table

var rec = new GlideRecord('u_issue_task');

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

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

rec.query();

gs.info('Open Issue Tasks' + rec.getRowCount());

if(rec.next()){

gs.info('Inside if');

gs.addErrorMessage('All issue taks should be closed before resolving/closing issue ' + current.number + ' record'); // use valid number field

current.setAbortAction(true);

}
else
{
current.state = '3';
current.update();

action.setRedirectURL(current);
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

vijay23
Tera Contributor

Hi All,

Thanks for Immediate reply

I tried to execute the code with  rec.addQuery('state','!=','3'); but, it is directly executing the else condition in my code 

 

Hi,

Did you check the state value is 3 for closed on your custom table

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@vijay

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader