Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
def script = '''
  function issueChanged() {
    var issueKey=AJS.$("#log-work-issue-picker").val()[0];
    console.log("Issue key:" + issueKey);
    
    fetch("/rest/api/2/issue/ERP-75").then(function(response) {
      if (response.status === 200) {
        response.json().then(function(data) {
          console.log(data);
        });
      }
    });
  }
  AJS.$(document).on("change", "#log-work-issue-picker-field", function(evt) {
    setTimeout(issueChanged, 10);
  });

'''

worklogPreEntryParameters.jsScript = script;

return worklogPreEntryParameters;

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.

Code Block
import com.atlassian.jira.component.*;
import com.deniz.jira.worklog.data.attr.AttrType;
import com.deniz.jira.worklog.data.attr.AttrValue;
import com.deniz.jira.worklog.services.attr.AttrTypeService;
import com.deniz.jira.worklog.data.attr.AttrValueImp;
import com.deniz.jira.worklog.scripting.WorklogPreEntryParameters;
import com.deniz.jira.worklog.services.*;
import com.atlassian.jira.issue.*;
import java.util.*;
import org.slf4j.*;
 
def issueManager = ComponentAccessor.getComponent(IssueManager.class);
def issue = issueManager.getIssueObject(worklogPreEntryParameters.issueKey);
 
def attrTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(AttrTypeService.class);
def attrTypes = ComponentAccessor.getOSGiComponentInstanceOfType(AttrType.class);
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager.class);
 
def selectCustomField = customFieldManager.getCustomFieldObject(10400); //Getting custom field with custom field id
def selectedOption = issue.getCustomFieldValue(selectCustomField);
 
def singleSelectAttrId = attrTypeService.getAttrTypeWithName("Single Select Attribute").get().ID; //Getting attribute with attribute name
def singleSelectAttr = worklogPreEntryParameters.attrTypes.find {element -> element.id == singleSelectAttrId};
def singleSelectAttrValues=singleSelectAttr.attributeValues;
 
def attrNames=singleSelectAttrValues.collect {it -> it.name};
for(option in attrNames){
    def AttrOption=option.toString();
    if(AttrOption == selectedOption.toString()){
      def attrImp=singleSelectAttrValues.find {it -> it.name==AttrOption};
      attrImp.setDefaultValue(true);
    }
  }