Hi Community,
My use-case:
My requirement is:
Please guide on how to code the above configuration on Create screen using Scriptrunner Behavior for Jira Cloud and Any sample code will be a great help to build the same logic.
Thanks
Hello @Digvijay Singh Gehlot ,
Replace customfield_12345 with the actual custom field ID of "Project Version" and give this a try.
// Copy "Project Version" from Parent issue to Child issue on Create screen
const parentField = getFieldById("parent");
const projectVersionField = getFieldById("customfield_12345");
async function run() {
parentField.on("change", async () => {
const parentKey = parentField.getValue();
if (!parentKey) {
projectVersionField.setValue(null);
return;
}
const parentIssueRes = await makeRequest(`/rest/api/2/issue/${parentKey}`);
if (!parentIssueRes || parentIssueRes.status !== 200) {
logger.warn(`Could not fetch Parent issue ${parentKey}, status=${parentIssueRes?.status}`);
return;
}
const parentIssue = parentIssueRes.body;
const parentProjectVersion = parentIssue.fields["customfield_12345"];
projectVersionField.setValue(parentProjectVersion || null);
});
}
await run();
Is it really needed on the Create screen to allow the user to adjust it, or will it always be the Project Version from the parent?
If the latter, there's a far simpler solution using automation rules. You could create an automation rule to trigger when a work item is created, then simply write the value from the parent to the children. You could even detect changes to that field on the parent and cascade them to the children whenever it changes - effectively syncing it.
Another option on that same thought process is using a Scripted Field in Scriptrunner, but it's a little more complicated if you're not too familiar.
Food for thought :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Adam Mason
Thank you for your message.
Yes, as per customer requirement, user should have the flexibility to change the Parent-key in Parent field so that they can see what values are coming from the Parent issue to Child fields on field value change on Create screen and decide which Parent they have to select before submitting a new Child issue.
I have configured and tested that suggested Jira rule but the changes are happening after the Child issue is created. But requirement is, user should see the values of Parent fields on Child issue as soon as a Parent-key is selected in Parent field before clicking on Create button on Create screen.
It would be great if you can help me with Scripted field - sample code in Scriptrunner to achieve my use-case?
Thanks
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_ ,
Thank you for helping me out with similar use case in Jira DC: https://community.atlassian.com/forums/Jira-questions/Copy-Parent-Field-Values-to-Child-When-Selecting-Parent-in/qaa-p/3016022#M1123744
May you also guide me with the sample code for Scriptrunner Behavior for Jira Cloud?
Thanks in advance.
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.