Pre Worklog Entry Scripts

These scripts are run just before “Log Work Dialog” or “Log Work Custom Field” is displayed and allows you to define preset values or modify worklog attributes.

 

Hide Worklog Attribute Depending on Issue Custom Field Value

Following script checks value of a “Single Select” custom field and if value of this field is “Development” it removes “Requirement Analysis” value from “Type of Work” worklog attribute.

import com.atlassian.jira.component.*; import com.atlassian.jira.issue.*; import org.slf4j.*; //please enable logging for package "com.deniz.jira.worklog.scripting" from Administration/System/Logging and Profiling Logger log = LoggerFactory.getLogger(com.deniz.jira.worklog.scripting.ScriptingService.class); def issueManager = ComponentAccessor.getComponent(IssueManager.class); def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager.class); def issue = issueManager.getIssueObject(worklogPreEntryParameters.issueKey); log.debug("issue:{}", issue); def selectCustomField = customFieldManager.getCustomFieldObject(10901L); def selectedOption = issue.getCustomFieldValue(selectCustomField); //instance of com.atlassian.jira.issue.customfields.option.Option log.debug("Selected Option:{}", selectedOption); if (selectedOption.optionId == 10404) { //if you want you can also check selectedOption.value == "Development" log.debug("Removing 'Requirement Analysis' from 'Type of Work' options"); def workTypeAttr = worklogPreEntryParameters.attrTypes.find {it.name == "Type of Work"}; if (workTypeAttr != null) { def reqAnalysisWorkAttr = workTypeAttr.attributeValues.find {it.name == "Requirement Analysis"}; if (reqAnalysisWorkAttr != null) { workTypeAttr.attributeValues.remove(reqAnalysisWorkAttr) } } } return worklogPreEntryParameters;

 

Hide Remaining Estimate

Following script injects a JavaScript to Log Work Dialog and this JavaScript code sets remaining estimate strategy to “Auto” and hides “remaining estimate” section of worklog dialog.

worklogPreEntryParameters.jsScript = ''' AJS.$("#log-work-adjust-estimate-auto").prop("checked", true); AJS.$("#wp-fg-estimates").hide(); '''; return worklogPreEntryParameters;

 

Set Default Value of Worklog Attribute Depending on User

Following script set default value of “Invoice Number” attribute to “12345” if current user is “admin”.

import com.atlassian.jira.component.*; import com.atlassian.jira.security.*; def authContext = ComponentAccessor.getJiraAuthenticationContext(); def loggedInUser = authContext.getLoggedInUser(); def invoiceNumberAttr = worklogPreEntryParameters.attrTypes.find {it.name == "Invoice Number"}; def defaultInvoice = ""; if (loggedInUser.key == "admin") { defaultInvoice = "12345" } if (invoiceNumberAttr != null) { script = ''' var $invoiceNumber = AJS.$("#wa_%s"); if ($invoiceNumber.val() === "") { $invoiceNumber.val("%s"); } '''; worklogPreEntryParameters.jsScript = String.format(script, invoiceNumberAttr.id, defaultInvoice); } return worklogPreEntryParameters;

 

Depending on User’s Group Sets Default Value of a Worklog Attribute

Assume that we have an attribute “Work Location” that can have one of the two values: On-site or Off-shore. The default is On-site. The following script checks if a user is in the group “all-Onsite” and if not, it sets the attribute value as Off-shore on the dialogue.

 

Hide a Worklog Attribute Depending on User’s Group

Following script checks “user group” of current user and show “Invoice Number” worklog attribute only if user is member of “finance-users” user group.

 

Making WorklogPRO’s “Log Work” Dialog Very Similar To Jira’s Own “Log Work” Dialog

In this script we are removing every WP specific items such as “issue picker”, “user selector”, “period selector”, “navigator” and “copy comment to issue” feature. Note that, you don’t need to remove “Account” and “Worklog Attributes” because they are only visible if you create them. So, if you don’t want them, don’t create them.

Change Default Value of Account if Issue Has Specific Key

This script changes account of an issue if issue key has specific value. You can modify it to check user, user-group, project, roles etc. It only searches accounts at first level for simplicity. If you want to set a child account, you need to make a recursive search for the account. If you now account ID, you can directly use it instead of searching it.

Setting Default Values for Account & Attributes Depending on Project

 

Make Copy to Issue Comments Checked Depending on Project

Set Time Spent Field to a Default Value

 

Get Issue Details Every Time When Issue Picker Changes

Assigning The Selected Option of Select List(single choice) Custom Field to Single Select Type Worklog Attribute Value as a Default

This script gets the select list(single choice) type custom field value defined for the issue then assign to the single select attribute value as a default value in WorklogPro dialog. Custom field id and attribute name in the corresponding lines of script are needed to be specified. This script runs in 'Before Worklog Dialog Display' script type.

The script above is assigning the value of the custom field of the issue to the relevant attribute values as a default before the worklog dialog was opened. However, if the issue is changed in the issue picker section while the worklog dialog was open, these values are not updated according to the selected issue. To update the attribute values according to the selected issue when the user changes the issue while the dialog is open ,the script below is needed to be used. The script below assigns the custom fields values specified with the IDs customfield_10500 and customfield_10501 to the attributes as a default by assigning the corresponding select type html elements which have IDs 'wa_10' and 'wa_11'. As with the script above, the important part here is that both the custom field and the attribute have the same values.

Removing 'Remaining Estimate' field of Log Work Custom Field

This script works in ‘Before Worklog Dailog Display' script type, it provides 'Remaining Estimate’ field to be removed from log work custom field.

Resize of Worklog Dialog

 

Resize of Worklog Dialog

Set an error message below the issue, if value of a field is not provided. In the below example, we are checking the value of “STAR Reference” field and if it is not provided, we are showing an error message just below the issue.