Moving data from one field to another
Asked by Sherry Nightingale:

Hi - I have two custom fields of the same name that are different field types

I want to move data from one field type to another field type

I'm assuming this can be done via an automation rule?

I have the two IDs

PO number 10274 multi line

PO Number 10539 single line

I want to move the data from 10274 to 10539

I'm new to automation rules - any help on what the rule should be would be greatly appreciated

Thanks

Sherry


Answers:
author: John Funk
body: Hi Sherry,

I usually start by changing the name of the field I am getting rid of, to maybe add a period at the end or someway to differentiate between the fields.

Then create a Schedule trigger rule - you can use whatever time period you like. Then add a JQL for "old field name" is not empty where old field name is the exact new name of the field you might have change above. If you have multiple open tabs and you are switching between them, be sure to refresh the rules tab after the name change and before creating the rule.

You might even want to have a JQL like field one is not empty and field two is empty. Do your JQL validation just to be sure. You also might want to create a JQL for just one issue (key = ABC-123) to test it out first.

Then add an action for Edit Issue and select field two (the field you are keeping). Then click the 3 dots beside the box under the field name and select Copy.

Then click on the result in the box and change the value for "Field to copy value from" to field one (the name change one).

Click Close, then Next.

Then Turn Rule on. I usually have it with a name like Bulk change.

Then in the top right of the rule tabs on the rule, click the 3 dots menu and select Run rule.

This will copy over all of the values.

Then be sure to turn the rule off so it won't keep running for every time period.

Then as you have additional future needs, update the fields, turn the rule back on and run it. Then turn the rule back off.

comments: author: Sherry Nightingale
body: [@John Funk](/t5/user/viewprofilepage/user-id/7148)

Thanks for the information but I can't get it to work and I think this is because i'm trying to move data from a multi line text field to a single line text field?


author: John Funk
body: Yes, going in that direction will be a problem. You would need to clean your data up so that it only has one line of data in the multi-line field. And make sure it doesn't exceed the limit for short text field.


author: Sherry Nightingale
body: Thanks [@John Funk](/t5/user/viewprofilepage/user-id/7148)

The majority is only on one line and all data is within the 255 character limit - i'm assuming then that it isn't the different field type that is causing the problem?


author: John Funk
body: You can try it with just a single issue that you know is within the character limit and see if it barfs on it. Just use key=ABC-123 for the JQL in the scheduled trigger - of course with your issue key.


author: Judit Gal
body: Hi [@John Funk](/t5/user/viewprofilepage/user-id/7148) , I am working with Sherry on this problem. This is working: {{issue.Description.split(" ").get(0)}}

The problem is the field name we want to copy from contains a space character "PO number". How can I modify the expression above changing "Description" to "PO number"?


author: Judit Gal
body: sorry, that works if the separator is a space character, we need a line break but "\\n" doesn't work. So there is two problems with this approach.


author: Judit Gal
body: right, I cracked it. it was that simple: {{issue.customfield_10274.split("\\n").get(0)}}


author: John Funk
body: Very nice - glad you got this going. Yeah, you just need to change out the name of the field or use the customfield ID as you have.


author: Judit Gal
body: Out of interest, is it possible to use regex to change line breaks in the filed before copy (so we wouldn't need to manually edit those which used multiple lines)?


author: John Funk
body: Do you have a specific example?


author: Judit Gal
body: For example we have a custom field which is Paragraph type (multiline) and we want to search and replace all line break to a comma.

It is connected to the original question because the best would be if we could change the text to single line (by changing the line breaks) and then copy to the short text field.

note: we want to decommission the multiline custom field.

so the automation steps would be:

1. remove line breaks

2. copy text to short text custom field

3. delete string from the multiline custom field


author: Bill Sheboy
body: Hi [@Judit Gal](/t5/user/viewprofilepage/user-id/5368184)

There are at least two ways to do that:

* Use the replace() function for basic text replacements: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#replace-String-target--String-replacement->
* Use the replaceAll() function when you want to use a regular expression for the replacements: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#replaceAll-String-regex--String-replacement->

For example: {{issue.description.replace("\\n", ",")}}

Using one of these to replace newlines is helpful as the match() function struggles with those characters, and so the fix is to chain the functions.

Kind regards,  
Bill


author: Judit Gal
body: Thank you [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) , I was on that path already but it took me a while to figure out why this {{issue.description.replaceAll("(\\n)","; ")}} insert the "; " twice. It is so easy once you know :P the solution is

{{issue.description.replaceAll("(\\n**+**)","; ")}}

(of course the change will be do in a custom field I just use the description for testing)

Thank you very much to all the help, I think we have all we need

Bets Regards,

Judit


author: Sherry Nightingale
body: [@John Funk](/t5/user/viewprofilepage/user-id/7148)

Thanks for the information but I can't get it to work and I think the issue is because i'm moving from a multi line field type to a single line field type?

Thanks

Sherry


author: Lisa Forstberg
body: Hi [@Sherry Nightingale](/t5/user/viewprofilepage/user-id/5299338)

Ah, I have seen this need also. You want an automation to copy the available options in one custom field to another custom field right?

Mostly an automations actions is about updating/changing issues, not the underlying configuration. I would LOVE to have some of that though. I can't seem to find any actions that is about managing the configuration via automations.

Even if you try to hack it via one dummy issue with all values applied in your multi list and in a automation try to do copy value from one field to the other (with a smart value variable) it doesn't push in the values.

#### Other solutions {#toc-hId-351503316}

* I think [Scriptrunner](https://docs.adaptavist.com/sr4jc/latest/features/built-in-scripts/copy-custom-field-values-to-another-field) have a built-in script that copy field values from one field to another that may be what you are after. If you have scriptrunner :S
* I know that the external import \> csv import lets up update values to a custom field so that might be a workaround instead of copying and pasting manually.
* Another solution when I see you are on Premium...why not use Assets to manage your PO's in one central location, with a lot more bells and whistles than a ordinary select list custom field? With an asset custom field it is easy to change between it being multi select or single select.

best of luck!

/L

comments: author: Sherry Nightingale
body: Thank you [@Lisa Forstberg](/t5/user/viewprofilepage/user-id/5101516)

We do have scriptrunner but we're going to be getting rid of it soon - 99% of what we need can be achieved with automations that don't come with a cost

Regarding Assets - we moved to Cloud 8 months ago and there is a lot of legacy that i've inherited - Assets is in my backlog to look at but for now i'm spending time de-cluttering because there is a lot of mess


author: Lisa Forstberg
body: I see, and when I read about the SR they also caveat for the multi to single problem. I think your best bet is to use the import csv workaround, especially if your list is long.

br

Lisa


Tags: cloud

jira-cloud