Prevent Deletion of Worklogs
Although you can control who can delete worklogs with project’s permission schema you may not want to implement more complex requirements to control who can delete which worklogs.
Worklogs with an Invoice Number can't be Deleted
If you have created an “Invoice Number” worklog attribute and a worklog is created as a part of an invoice you may not want to allow a user to delete that worklog.
import com.atlassian.jira.component.ComponentAccessor;
import com.deniz.jira.worklog.services.attr.AttrTypeService;
//We need to load WorklogPRO classes differently using getOSGiComponentInstanceOfType
def attrTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(AttrTypeService.class);
def invoiceNumberAttrType = attrTypeService.getAttrTypeWithName("Invoice Number").get();
if (invoiceNumberAttrType == null) {
return; //there is no "invoice number" attribute
}
def invoiceNumber = worklogAttributes.get(invoiceNumberAttrType.getID());
if (invoiceNumber != null) {
return "Worklogs with an invoice number can't be deleted!"
}