Date: Fri, 29 Mar 2024 11:45:17 +0000 (UTC) Message-ID: <2030711724.35.1711712717006@0012a8d4ca57> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_34_291393936.1711712717006" ------=_Part_34_291393936.1711712717006 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
We can't implement every customer requirements in WorklogPRO, we don't h= ave necessary resources, but also our customers has conflicting requirement= s. For this reason we have decided to allow our customers to customize Work= logPRO behaviors with Groovy scripts. You can execute various scripts = when logging work, approving timesheets. These scripts can be run before an= action is performed like logging work, after an action. When scripts are r= un before an action, you can cancel the action by returning a non-null resu= lt from worklog script.
When writing your scripts please refer to our Java API to see avai= lable methods and data structures.
Consider the case when logging work or deleting work. Worklog verif= ication highly depends on customers' requirements. To allow each customer t= o build his own verification logic we have decided to create a scripting in= terface for worklog verification. You can now write your own Groovy script = to verify worklog entry, update, move or delete operation. "Create/Update"&= nbsp;script is executed every time when some tries to log work on WorklogPR= O's 'Log Work Dialog' or 'Log Work Custom Field'. "Delete" script is executed every ti= me when someone tries to delete a worklog. When moving worklog from an issu= e to another first "Delete" script is executed and after that "Create/Updat= e" script is executed.
"Pre-Worklog Entry" is not a verification script, it is provides opportu= nity to modify worklog dialog content or worklog custom field content befor= e it is displayed to user. Using this script you can hide some attributes d= epending on custom conditions or show preset values to user. This script is= passed "worklogPreEntryParameters" which is an instance of "com.deniz.jira= .worklog.scripting.WorklogPreEntryParameters" and your script should also r= eturn an instance of this object.
You can also access various Jira services and WorklogPRO services using = com.atlassian.jira.component.ComponentAccessor. You can chec= k JavaDoc of WorklogPRO classes from here. Please check exampl= e scripts for more detailed usage scenarios.
Configuring worklog scripts requires Jira Administrator, Jira Sy= stem Administrator. Due to security constraints WorklogPRO Administrators c= an't update script. Since you can write arbitrary code and use all Jira ser= vices inside the script a script can do anything to your Jira instance alth= ough it is executed with privilege of logged in user (the user creating/upd= ating/deleting worklog).
You can use println statements to log values to Jira proce= ss's standard output for debugging purposes, not atlassian-jira.log file. Y= ou can use SLF4J logging to log to atlassian-jira.log file if you want. If = you want to use logging please set debug level for the package "com.deniz.j= ira.worklog.scripting" and use following code to add debug messages to your= script.
import = org.slf4j.*; //please enable logging for package "com.deniz.jira.worklog.scripting" from= Administration/System/Logging and Profiling Logger log =3D LoggerFactory.getLogger(com.deniz.jira.worklog.scripting.Scr= iptingService.class); log.debug("This is debug message");
This script access various Jira and WorklogPRO services using ComponentA= ccessor class. Note that to access WorklogPRO services you need to use "getOSGiComponentInstanceOfType" method. This script checked whether a= "Billable" boolean attribute exist. If it doesn't exist logging work is al= lowed. If it exists, check worklog is marked as billable. If it is billable= , it checks whether the current user has "Service Desk Team" role in the pr= oject. If the user doesn't have "Service Desk Team" role, logging work is d= isallowed.
Error rendering macro 'code': Invalid value specified for par= ameter 'firstline'import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.security.JiraAuthenticationContext; import com.atlassian.jira.security.roles.ProjectRoleManager; import com.deniz.jira.worklog.services.attr.AttrTypeService; def authenticationContext =3D ComponentAccessor.getJiraAuthenticationContex= t(); def projectRoleManager =3D ComponentAccessor.getComponent(ProjectRoleManage= r.class); //We need to load WorklogPRO classes differently using getOSGiComponentInst= anceOfType def attrTypeService =3D ComponentAccessor.getOSGiComponentInstanceOfType(At= trTypeService.class); def billableAttrType =3D attrTypeService.getAttrTypeWithName("Billable").ge= t(); if (billableAttrType =3D=3D null) { return; //there is no billable attribute } def isBillable =3D worklogAttributes.get(billableAttrType.getID()); def loggedInUser =3D authenticationContext.getLoggedInUser(); def serviceDeskTeamRole =3D projectRoleManager.getProjectRole("Service Desk= Team"); def project =3D worklog.getIssue().getProjectObject(); println(worklogAttributes); if (isBillable =3D=3D "yes") { //boolean attributes are has either "no" or = "yes" value. if (!projectRoleManager.isUserInProjectRole(loggedInUser, serviceDeskTeam= Role, project)) { return "Only Service Desk Team can register billable worklogs!" } }
import com.deniz.jira.versioning.CmpVersionMappingService; import com.deniz.jira.worklog.scripting.WithPlugin; import com.atlassian.jira.component.ComponentAccessor; @WithPlugin("com.deniz.jira.versioning") //this is the plugin key. you can= get it from "manage apps" screen def cmpVersionMappingService =3D ComponentAccessor.getOSGiComponentInstance= OfType(CmpVersionMappingService.class);
import com.atlassian.jira.component.ComponentAccessor import org.slf4j.*; import com.deniz.jira.worklog.*; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.Issue; import groovy.sql.Sql; import java.sql.*; def issueId =3D worklog.getIssue().getId().toString(); def issueKey =3D worklog.getIssue(); def project =3D issue.getProjectObject().getId(); String SQLStmt =3D """INSERT INTO mydb.schema.table VALUES (""" + issueId += """, '""" + issueKey + """', """ + project + """) """; // username and passowrd def props =3D new Properties(); props.setProperty("user", "theuser"); props.setProperty("password", "thepassword"); def driver =3D Class.forName('net.sourceforge.jtds.jdbc.Driver').newIns= tance() as Driver; def conn =3D driver.connect("jdbc:jtds:sqlserver://SERVERNAME:1433/INST= ANCE", props); =20 if (conn) { def sql =3D new Sql(conn) try { def result =3D sql.executeQuery(SQLStmt); sql.close() conn.close() } catch (Exception e){ log.error(e.toString()) } } else { log.error("Could not connect to SQL database.") }