Hi,
I'm using the below script to create sub-tasks using Automation and working fine. The issue I'm facing here is that I'm unable to copy the value of Software Sub-Product relevant values based on the Software Products like like Adobe, Microsoft. Adobe has Software Sub-Products like Animate and Microsoft has Copilot. Each Sub-task is getting created for each Adobe and Microsoft. I want to copy Animate under Software Sub-Product field in the Adobe sub-task and Copilot under Software Sub-Product field for Microsoft Sub-task.
Both Software Product and Software Sub-Product Fields are Asset object field (multi-select).
Here is the Script I'm using -
Hi @Sriharsha
Based on what condition do you want the Sub-Tasks to be created?
I am asking this because instead of using Automation to create the Subtasks, you can do it directly via ScriptRunner. When the Subtask is created, it can automatically pass the Asset value to the field.
I am looking forward to your feedback and clarification.
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ , thank you for your response!
I want the sub-tasks to be created based on the field called Software Sub-Product.
I have placed this script in the Automation Action :
I'm able to create the sub-tasks but unable to copy the relevant sub-products like Animate for Adobe Sub-task and copilot for Microsoft Sub-Task. I'm getting both the values (Animate & Copilot) in both the Sub-tasks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sriharsha,
In your last comment, you asked:-
You mean if I use the above same script in the Workflow post function, will it work?
It depends. As I asked in my previous comment:-
Based on what condition do you want the Sub-Tasks to be created? I need to know this first.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have an Asset Field which fetches Users from an Object Schema and based on number of users, I need to create Sub-tasks based on the Software Sub-Products selected for each user. Let's say I have selected two users and 3 Software Sub-Products. For one user, 3 Sub-tasks (one for each Software Sub-Product selected).
In total 6 ( 3 for each user) in this case.
Best Regards,
Sriharsha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sriharsha
I will work on an example and get back to you once I have an update.
Thank you and Kind regards,
Ram
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.
Hi @Sriharsha
Below is a sample working code for your reference:-
import com.adaptavist.hapi.jira.assets.Assets
import com.adaptavist.hapi.jira.users.Users
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
def selectedUsers = issue.getCustomFieldValue('Selected Users') as List<ObjectBean>
if (issue.issueType.name == 'Task') {
selectedUsers.each { selectedUser ->
issue.createSubTask('Sub-task') {
setSummary('Test Sub-Task')
setDescription('Testing Sub-Task 123')
def username = Assets.getById(selectedUser.id).getAttributeValues('Username').toString().replace("[StringValue(value=",'').replace(')]','').trim()
setAssignee(Users.getByName(username))
def id = Integer.parseInt(Assets.getById(selectedUser.id).getAttributeValues('Software').toString().substring(25, 27).trim())
Assets.getById(id).each {product ->
setCustomFieldValue('Assigned Product', product)
}
}
}
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modifications.
In the code above, I have used ScriptRunner's HAPI Isseu Sub-Task Creation feature along with the Assets feature to simplify the code.
I am able to get the Sub-task to be created with the correct product in the Asset field that is set to the User without any need for Automation.
Below is a screenshot of the Post-Function configuration:-
Also, in my environment, I have configured an example Asset configuration, which most likely will not match yours. So, you must play around with the code accordingly.
Below are screenshots of my Asset configuration:-
1. The User Asset config
2. The Adobe Asset config
3. The Microsoft Asset Config
Below are some test screenshots for your reference:-
1. On the create screen two users are selected from the Asset field both who are Adobe product users.
2. Once the issue is created 2 sub-tasks are also created.
3. In the first sub-task, the Asset is set to Photoshop, the Assignee is set to the User selected in the Asset
4. Similar to number 3, the Assignee is set to the User selected in the Asset. However, this time, the Asset is set to Acrobat.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much, @Ram Kumar Aravindakshan _Adaptavist_ ! I will check and update you ASAP.
Best regards,
Sriharsha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sriharsha
Has your question been answered?
If yes, please accept the answer provided.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Please find the script I have worked upon which creates linked issues based on the values of Software Vendor field (Asset Object multi-select) which has options. Example while creating the request, if I select options like Adobe, VMWare, it creates two linked tickets. There's another field called Software - Sub Product, which has the child values of Software Vendor field. Please find the screenshots attached.
If you look at the AC Software 3.PNG file, It should only show the Sub Products related to Software Vendor (Adobe) and not other vendor products like X-Ways.
X-ways has another linked ticket created and it should show X-ways related Sub- Products and not Adobe related options.
Attached is my script I have been executing using an Automation Action - Run a Script (AC Software 4.PNG) -
/////////////////////////////////////////////////////////////////////////////////////
import com.adaptavist.hapi.jira.assets.Assets
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.fields.CustomField
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
Long softwareVendorFieldId = 32320L // Multi-select asset object field for "Software - Vendor"
Long softwareSubProductFieldId = 32321L
def issueManager = ComponentAccessor.getIssueManager()
MutableIssue parentIssue = issueManager.getIssueObject(issue.id) // Ensure issue is available
parentIssue.setAssignee(null)
// Fetch the custom fields for "Software - Vendor" and "Install For"
CustomField softwareVendorField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(softwareVendorFieldId)
CustomField softwareSubProductField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(softwareSubProductFieldId)
def selectedOptions = parentIssue.getCustomFieldValue(softwareVendorField) as List<ObjectBean>
def softwareSubProductValues = parentIssue.getCustomFieldValue(softwareSubProductField) as List<ObjectBean>
if (selectedOptions) {
selectedOptions.each { option ->
log.info("Selected option: " + option.toString())
createServiceRequestForOption(parentIssue, option, softwareVendorField, softwareSubProductField, softwareSubProductValues)
}
}
void createServiceRequestForOption(MutableIssue parentIssue, def option, CustomField softwareVendorField, CustomField softwareSubProductField, def softwareSubProductValues) {
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
IssueFactory issueFactory = ComponentAccessor.getIssueFactory()
IssueManager issueManager = ComponentAccessor.getIssueManager()
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
def attachmentManager = ComponentAccessor.getAttachmentManager()
// Create a new Service Request instance
MutableIssue serviceRequest = issueFactory.getIssue()
// Set the necessary fields for the service request
String reporterName = parentIssue.getReporter()?.getDisplayName() ?: "Unknown Reporter"
String cleanedOption = option.toString().replaceAll(/\s*\(.*?\)\s*/, "")
serviceRequest.setSummary("Software Request: " + cleanedOption + " for " + reporterName)
serviceRequest.setIssueTypeId("22601") // Replace with Software Sub Request issue type ID
serviceRequest.setProjectObject(parentIssue.getProjectObject())
serviceRequest.setReporter(parentIssue.getReporter())
serviceRequest.setDescription(parentIssue.getDescription())
serviceRequest.setPriority(parentIssue.getPriority())
// Unassign the Service Request
serviceRequest.setAssignee(null)
// Copy the "Software - Vendor" field value (current option) to the service request
serviceRequest.setCustomFieldValue(softwareVendorField, [option]) // Only set the current option
// Copy the "softwareSubProductField" value to the service request (copying all values from the parent)
if (softwareSubProductValues) {
serviceRequest.setCustomFieldValue(softwareSubProductField, softwareSubProductValues)
}
// Store the new linked issue
issueManager.createIssueObject(user, serviceRequest)
def parentAttachments = attachmentManager.getAttachments(parentIssue)
parentAttachments.each { attachment ->
attachmentManager.copyAttachment(attachment, user, serviceRequest.key)
}
issueLinkManager.createIssueLink(parentIssue.id, serviceRequest.id, 10003L, null, user)
log.info("Service Request '${serviceRequest.summary}' created, attachments copied, and linked successfully.")
/////////////////////////////////////////////////////////////////////////////////////
Could you please help me fix my code.
Best regards,
Sriharsha
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.