Hello there,
i have a basic requierement : i want to change a customfield type from Number to text.
For that, i create a new custom field and wrote a script console (threw scriptrunner) and copy paste the value from my origin field to destination field.
at the end of my script i had the function setCustomFieldValue.
but it seems to not working becasue i didnt see any change in my log.
Please find my source code below:
SearchService.ParseResult parseResult = searchService.parseQuery(user, JQLsearch)
//checking the JQL is valid
if (parseResult.isValid())
{
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
listResults = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
for(MutableIssue issueSearch:listResults)
{
log.debug("Issue en cours " + issueSearch.id)
def cforiginevalue = issueSearch.getCustomFieldValue(cforigine)
def cfdestinationvalue = issueSearch.getCustomFieldValue(cfdestination)
log.debug("cforiginevalue avant " + cforiginevalue.toString())
log.debug("cfdestinationvalue avant " + cfdestinationvalue)
issueSearch.setCustomFieldValue(cfdestination, cforiginevalue.toString())
issueSearch.setCustomFieldValue(cforigine, null)
log.debug("cforiginevalue aprés " + cforiginevalue)
log.debug("cfdestinationvalue aprés " + cfdestinationvalue)
}
}
else
{
log.error("Invalid JQL: " + JQLsearch)
}
please my log result below:
2018-07-09 17:03:25,655 DEBUG [jira.groovy]: Issue en cours 11689
2018-07-09 17:03:25,662 DEBUG [jira.groovy]: cforiginevalue aprés 1221211.0
2018-07-09 17:03:25,662 DEBUG [jira.groovy]: cfdestinationvalue avant 1
2018-07-09 17:03:25,662 DEBUG [jira.groovy]: cforiginevalue aprés 1221211.0
2018-07-09 17:03:25,662 DEBUG [jira.groovy]: cfdestinationvalue aprés 1
Does i miss something ? because the issueSearch.setCustomFieldValue works well on a post function in a workflow.
Regards,
Olivier
Hello,
You should add the updateIssue method like this:
issueSearch.setCustomFieldValue(cfdestination, cforiginevalue.toString())
issueSearch.setCustomFieldValue(cforigine, null)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Also add import:
import com.atlassian.jira.event.type.EventDispatchOption
Hello alexey,
its work well.
but i dont get it because i use the same way to reset a date in a workflow transition post function, and i didn't need a update issue methode...
Do you know why ?
Thank anyway
Olivier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have a look at the workflow transition. Your post function stays before store data and reindex. That is why it works. But in script console you must store and do reindex manually. That is exactly what udpateIssue does.
If you put your post function last in the list of post functions, it will not work as well. It would need the udpateIssue method
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.
You are welcome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alexey,
I have one more question (sorry)
The origine field is a number field and it contains "3.2578777777E10".
My destination field is a string.
But i would like to copy in my destination field "32578777777"
Do you have any way to reach my goal?
If i copy the originefield.tostring() value i get the scientific mode in my destination field...
I am stuck here ...
Olivier
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's a bit of a java trick - you need to tell it how to format the string as you convert it.
Assuming that the variable myNumber is a number, the plain Java for this is below (I'm a bit fuzzy on Groovy and can't always get it right)
DecimalFormat decForm = new DecimalFormat("#");
decForm.setMaximumFractionDigits(6);
String myString = decForm (myNumber);
You probably want to change the "6" I've pasted in from my notes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
i found out how i can solved my probleme
i just added this line:
issueSearch.setCustomFieldValue(cfdestination, String.format("%.0f", cforiginevalue))
so far so good :)
once again thank for your support
Olivier
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.