Hi @Eis3an
I'm sorry, but I'm having trouble understanding your exact needs. Could you please provide some solid examples to clarify?
Hello,
Supposing i have a custom field of multi select. It contains 5 values (users) at the time of creation. Afterwards I edit this field at a certain transition to add 2 or more value to the field. Now i need a post function on this transition that will copy only the added users to another custom field.
This other custom field has a list of users (users working on the issue) already that should not be changed, only appended.
I hope am clear. Thanks for the response
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see,
Is the other custom field a text field where you only need an explanation of the change, or is it another multi-select field that only contains the newly added options? How about removing items? Lastly, if this transition is called multiple times, will it override?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the other custom field is a list that contains some permanent users that are working on this field that should not be bothered. in addition to these permanent users optional users that are added further during transitions should get appended or removed based on the initial custom field that list of new users invited to work. adding users has been solved using post function copy field value.
removing users is the tricky part.
yes this transition can be called multiple times.
(any users invited can decline even after they have accepted so their names once they removed from initial field must be automatically removed from other field without disturbing the permanent and other values in the second field)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It means that you need to write a script to achieve this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes my good sir i figured as much. i need help with the scripting in post functions.
mainly how to reference deleted field values. then compare it with another list to calculate the difference between the two lists then append
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I can't say I understand 100% but, from my understanding, I tried to scratch something which might help you start with.
I hope it helps...
async function updateUserList(issue) {
const initialField = issue.fields['customfield_XXXXX'] || [];
const secondaryField = issue.fields['customfield_YYYY'] || [];
const permanentUsers = ["permanent_user_1", "permanent_user_2"];
async function getUserDetails(userKey) {
const response = await api.asApp().requestJira(`/rest/api/3/user?key=${userKey}`);
return await response.json();
}
const permanentUserDetails = await Promise.all(permanentUsers.map(user => getUserDetails(user)));
const initialUserSet = new Set(initialField.map(user => user.accountId));
const secondaryUserSet = new Set(secondaryField.map(user => user.accountId));
const permanentUserSet = new Set(permanentUserDetails.map(user => user.accountId));
const usersToAdd = [...initialUserSet].filter(user => !secondaryUserSet.has(user));
const usersToRemove = [...secondaryUserSet].filter(user => !initialUserSet.has(user) && !permanentUserSet.has(user));
const updatedSecondaryUsers = [
...permanentUserDetails, // Add permanent users
...secondaryField.filter(user => !usersToRemove.includes(user.accountId)), // Keep existing users minus those to remove
...usersToAdd.map(user => ({ accountId: user }))
];
await api.asApp().requestJira(`/rest/api/3/issue/${issue.key}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
fields: {
[secondaryFieldId]: updatedSecondaryUsers
}
})
});
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Eis3an ,
Do you have the Power Scripts app? If not, would you consider using that one for this use case? I think it`s doable using Power Scripts and SIL scripting language. It can be done as a post function or even SIL Listener that reacts to field value change (without connection to any particular transition). Please let me know if that`s something you are interested in, and I`ll help you with the script itself.
Best regards,
Anna
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.