I have 2 jira issues that are known to have the same custom fields with names c1,c2,c3.
I have some js code on post work step automation that can copy the value from the source issue's c1 to the target issue's c1, but that only works for multiline text by reading from/writing to the "content" property inside the json structure associated with both fields/issues.
If c2 is not a multiline text but an assignee field or a time stamp then the code will fail to copy the value, as the property "content" does not exist in the custom field, instead I guess the "displayName" would need to be copied for the assignee and the "value" for a select field.
So I know that each c1/c2/c3 respectively are of the same kind in both source and target issue but I do not know what kind they are nor what property to copy. Is there some way to generalize this or do I need to check the kind of each ci and then derive the "right" properties to copy from it?
Thx,
Alex
Hi @Alexander Herz ,
Is there any specific reason you're using custom code for value copying and not Jira automation? I mean, with automation, it's quite easy to get the desired result, and it will work for all/most field types.
As for custom codes, I'd probably ask to maybe share what you've got so far (code itself) and maybe someone can jump in to give a hand on this. I, personally, don't play that much with customized coding.
Cheers,
Tobi
I have multiple template issue that contains text in various custom fields.
On post transition I want to copy a set of fields from a template issue to the current issue. It would be possible to "set the field value" using the existing post function but this has very long turn around times when the template text is updated (only a jira admin is allowed to change the post function but the jira admin does not maintain the template, so instead of implementing in a test instance and migrating the change to production by someone else, which is also quite error prone), we want to allow non jira admins to change the template text in the template issue (and do that in production), this is then picked up by out plugin on post and applied instantly.
We use the same logic for multiple things (we have more advanced templates where we also do validation of the template content etc) and we found sharing this code in git is overall more scalable and maintainable than having code fragments in the jira admin gui through script runner or automations.
As for the code, it is quite boring, I get the field from the template issue as json and then update the target issue with the same content (target and source issue both have the same custom fields I copy from/to).
The problem is that that json structure of different custom field types is different, e.g.: multiline texbox has a content property whereas assignee has a display name:
{ "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations", "id": "10066", "self": "https://XXXXXXX.atlassian.net/rest/api/3/issue/10066", "key": "TEST-2", "fields": { "customfield_10059": { "type": "doc", "version": 1, "content": [ { //..actual content structure } ] } } }
{ "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations", "id": "10066", "self": "https://tasking-test-aherz.atlassian.net/rest/api/3/issue/10066", "key": "TEST-2", "fields": { "customfield_10058": { "self": "https://XXXXXXX.atlassian.net/rest/api/3/user?accountId=712020%3Aa51b4530-0938-4d9b-9a0b-f77c0cf87e45", "accountId": "XXXXX", "emailAddress": "XXXXX@YYY.ZZZ", "avatarUrls": { "48x48": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:a51b4530-0938-4d9b-9a0b-f77c0cf87e45/a2cb79aa-5b35-4bcc-bf94-3867f38bf5ee/48", "24x24": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:a51b4530-0938-4d9b-9a0b-f77c0cf87e45/a2cb79aa-5b35-4bcc-bf94-3867f38bf5ee/24", "16x16": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:a51b4530-0938-4d9b-9a0b-f77c0cf87e45/a2cb79aa-5b35-4bcc-bf94-3867f38bf5ee/16", "32x32": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/712020:a51b4530-0938-4d9b-9a0b-f77c0cf87e45/a2cb79aa-5b35-4bcc-bf94-3867f38bf5ee/32" }, "displayName": "Alexander Herz", "active": true, "timeZone": "Europe/Berlin", "accountType": "atlassian" } } }
But I found the answer by trial and error, I can just take the complete json structure behind "customfield_XXX" and PUT it to "customfield_YYY" and it will work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!
Start here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.