Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Field required in Sub-Task based on Parent Issue Type

siva
Contributor
August 8, 2023

Hello there,

In my Jira workflow, I'm using the JMWE plugin validator for Sub: Task issue type (Field Required Validator). In this, I'm only making the "Time Spent" field required for particular groups, which means that only those group members need to fill out the "Time Spent" field.

And I configured this condition, and it works perfectly; see the condition below.

issue.get("issuetype")?.name == "Sub: Task" && (ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple1") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple2") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple3"))

But I need to make a minor change to this condition so that the "Time Spent" field in Sub:Task is only required when parent is Story type."

And I tried configuring the script below, but it didn't work. Please assist me in resolving this issue where I'm missing a step and I'm not a script specialist. Please guide me on this and your help appreciated.

(issue.get("issuetype")?.name == "Sub: Task" && parentIssue.get("issuetype")?.name == "Story") && (ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple1") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple2") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple3"))

Thanks,

Siva.

1 answer

1 accepted

1 vote
Answer accepted
David Fischer
Community Champion
August 8, 2023

Hi @siva 

The reason why this script didn't work is because the parentIssue variable only exists in the context of workflow extensions that relate to the parent issue of the current issue. 

In other cases, to access the parent of the current issue, use:

issue.parentObject

Thus to test the parent issue's issue type:

 issue.parentObject?.get("issuetype")?.name == "Story"
siva
Contributor
August 8, 2023

Hi @David Fischer 

Thank you for your prompt response, and I have replaced the script with the

 issue.parentObject?.get("issue type")?.name == "Story"

And when you try to move the status, it displays the error notice shown in the screenshot below. And here's the script I used in the validator. Please advise me on this matter.

(issue.get("issuetype")?.name == "Sub: Task" && issue.parentObject?.get("issue type")?.name == "Story") && (ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple1") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple2") || ComponentAccessor.getGroupManager().isUserInGroup(currentUser, "Siva Apple3"))

 Error message for issue type.png

Thanks,

Siva.

David Fischer
Community Champion
August 8, 2023

Hi @siva 

Sorry, autocorrect on my phone added a space between "issue" and "type" in my snippet. I have corrected it above. 

siva
Contributor
August 8, 2023

Hi @David Fischer 

Thank you very much for your assistance; the script works flawlessly, and I greatly appreciate your assistance.

Thanks,

Siva.

Suggest an answer

Log in or Sign up to answer