Hi,
I'm trying to implement a post-function in ScriptRunner Cloud that gets the Component Lead and set it as Approver, I have that script in SR Server:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.projectroles.ProjectRoleService;
import com.atlassian.jira.security.roles.ProjectRoleManager;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.security.roles.ProjectRole;
import com.atlassian.jira.security.roles.ProjectRoleActors;
import com.atlassian.jira.util.ErrorCollection;
import com.atlassian.jira.util.SimpleErrorCollection;
import com.atlassian.jira.user.util.Users
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
def sb = new StringBuffer() //sb is used to send string to logs
//Set the Project Roles readers/objects
ProjectRoleService projectRoleService = (ProjectRoleService) ComponentAccessor.getComponentOfType(ProjectRoleService.class);
ProjectRoleManager projectRoleManager = (ProjectRoleManager) ComponentAccessor.getComponentOfType(ProjectRoleManager.class);
ProjectManager projectManager = ComponentAccessor.getProjectManager();
ErrorCollection ec = new SimpleErrorCollection();
//Create the Global definitions
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def project
def userPropertyManager = ComponentAccessor.userPropertyManager
//Create the Specific definitions
def userList = new ArrayList();
def components = issue.componentObjects.toList()
if (components) {
userList.add(components?.first()?.componentLead)
}
//Prepare the field to set the values
CustomField customFieldApprovers = customFieldManager.getCustomFieldObjectByName("Approvers");
//set the value
issue.setCustomFieldValue(customFieldApprovers, userList)
//author of the change
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
//Submit the change
issueManager.updateIssue(user,issue,EventDispatchOption.ISSUE_UPDATED,true);
But I don't have enough experience to implement it on Cloud.
Can someone help with the translation? Any suggestions?
Thank you for the question.
In order for you to get the Component from the issue and by call Get Component API as documented here. To do this you would need the ID of the component which you can get from the components filed on the issue. Then to set the approver field update.
We in ScriptRunner for Jira Cloud have an example to get the component issue and update it with the Approver field value here. You can use the sample code as a guide to get the result/requirement that you want.
Hope this will help you.
Thank you.
Kind Regards
Kate
Thanks Kate,
I will try that Snippet, is there a way I see more examples? The Library is very limited. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, we do have other examples that you can refer to as guidance:
Hope this will help with your integration.
Thank you
Kind Regards
Kate
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.