Hi,
I am trying to copy first value of cascade select list to a custom text field "Business" and second value to security level.
I was earlier using below groovy on create issue post function to copy first value of cascade list to security level.
import org.apache.log4j.Category import com.opensymphony.user.User import com.googlecode.jsu.util.WorkflowUtils import com.atlassian.jira.issue.security.IssueSecuritySchemeManager import com.atlassian.jira.issue.security.IssueSecurityLevelManager import com.atlassian.jira.ManagerFactory import com.atlassian.jira.ComponentManager import org.ofbiz.core.entity.GenericValue def log = Category.getInstance("com.onresolve.jira.groovy.MriskCondition") ComponentManager componentManager = ComponentManager.getInstance() IssueSecurityLevelManager securityLevelManager = componentManager.getComponentInstanceOfType(com.atlassian.jira.issue.security.IssueSecurityLevelManager) IssueSecuritySchemeManager issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager() IssueSecurityLevelManager issueSecurityLevelManager = ManagerFactory.getIssueSecurityLevelManager() GenericValue srcProjectGV = issue.getProject() log.debug(srcProjectGV) def issueSecurityScheme = issueSecuritySchemeManager.getSchemes(srcProjectGV).size() == 0 ? null : issueSecuritySchemeManager.getSchemes(srcProjectGV)[0] User currentUser = componentManager.getJiraAuthenticationContext().getUser() def sourceFieldName = "customfield_10572" def sourceFieldVal = WorkflowUtils.getFieldValueFromIssue(issue, WorkflowUtils.getFieldFromKey(sourceFieldName)) sourceFieldVal = sourceFieldVal.getKeysAndValues() if ( sourceFieldVal != null ) { def business = sourceFieldVal[null][0] log.debug("business: '$business'" ) def secLevelGvList = issueSecurityLevelManager.getUsersSecurityLevels(issue.getGenericValue(), currentUser) log.debug(secLevelGvList) def secLevelGv = secLevelGvList.find ({ it.get("name") == "$business"}) log.debug(secLevelGv) if (secLevelGv) { log.debug ("Set ${issue.getKey()} to $business") issue.setSecurityLevel (secLevelGv) issue.store() } }
Now I want to copy first value to a text custom field and secend value to security level.
Could you please modify above script to solve my problem ?
Resolved using
cfBusiness.createValue(issue, business.toString())
Try this. I haven't tested it so you might need to do a few tweaks, but shows the idea.
import org.apache.log4j.Category import com.opensymphony.user.User import com.atlassian.jira.issue.security.IssueSecuritySchemeManager import com.atlassian.jira.issue.security.IssueSecurityLevelManager import com.atlassian.jira.ManagerFactory import com.atlassian.jira.ComponentManager import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.view.CustomFieldParams import com.atlassian.jira.issue.fields.CustomField def log = Category.getInstance("com.onresolve.jira.groovy.MriskCondition") ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() IssueSecurityLevelManager securityLevelManager = componentManager.getComponentInstanceOfType(com.atlassian.jira.issue.security.IssueSecurityLevelManager) IssueSecuritySchemeManager issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager() IssueSecurityLevelManager issueSecurityLevelManager = ManagerFactory.getIssueSecurityLevelManager() GenericValue srcProjectGV = issue.getProject() log.debug(srcProjectGV) def issueSecurityScheme = issueSecuritySchemeManager.getSchemes(srcProjectGV).size() == 0 ? null : issueSecuritySchemeManager.getSchemes(srcProjectGV)[0] User currentUser = componentManager.getJiraAuthenticationContext().getUser() def sourceFieldName = "customfield_10572" CustomField cf = customFieldManager.getCustomFieldObjectByName(customfield_10572) CustomFieldParams sourceFieldVal = issue.getCustomFieldValue(cf) as CustomFieldParams CustomField cfBusiness = customFieldManager.getCustomFieldObjectByName("Business") if (sourceFieldVal) { Collection values = sourceFieldVal.getAllValues() def business = values[0] def level = values[1] //set the text field issue.setCustomFieldValue(cfBusiness, business) log.debug("business: '$business'" ) //set security level def secLevelGvList = issueSecurityLevelManager.getUsersSecurityLevels(issue.getGenericValue(), currentUser) log.debug(secLevelGvList) def secLevelGv = secLevelGvList.find ({ it.get("name") == "$level"}) log.debug(secLevelGv) if (secLevelGv) { log.debug ("Set ${issue.getKey()} to $level") issue.setSecurityLevel (secLevelGv) issue.store() } } else { log.debug("Custom field not present on this issue") }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's copying the second list value (level) to security level but it's still not copying the first list value (business) to custom field (text field type).
No error reported in logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Used above changes and got this error:
The script failed : groovy.lang.MissingPropertyException: No such property: params for class: com.atlassian.jira.issue.customfields.view.CustomFieldParamsImpl
using this will update security level but not custom field value.
def business= sourceFieldVal.getFirstValueForNullKey()
def level = sourceFieldVal.getFirstValueForKey("1")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay try using :
def business= sourceFieldVal.getFirstValueForNullKey() def level = sourceFieldVal.params.getFirstValueForKey("1");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually the previous version of the code should work also. Can you print the value of business variable and see what it is ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think problem is not with getting the values but it's with setting the custom field value. I tried using level value for setting custom field value and security level both. Security level worked fine but customfield did not.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you checked if cfBusiness variable is not null ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.