Hello , After installing the plug_in Profields , and creating a Status Field with name(Statut) and added it to my project , so now i would like that when any issue transition from status (TO do) to (IN PROGRESS) , the fields of plug-in profield (Statut) must be changed to (in progress) also . So i create a post function and i create my script there , it's not working , maybe i have a problem in the class field .Can you help me to solve it please?
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.status.StatusField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.text.TextField
import com.deiser.jira.profields.api.value.ValueService
@WithPlugin("com.deiser.jira.profields")
Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.getKey())
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("KP");
Field statusField = fieldService.get("9") //ID of field Status
log.warn(statusField.toString())
def karim = valueService.getValue(issue.projectObject,(StatusField) statusField)
log.warn(karim.toString())
valueService.setValues(project,statusField , "rafik")
Hi Karim
I'm from DEISER and currently working in Profields product.
You have to make some changes in the script. I wrote the script from memory I hope it will work. I comment inline the changes inline, if you don't understand something, tell me please.
import com.atlassian.jira.component.ComponentAccessor
import com.deiser.jira.profields.api.field.item.status.StatusItemService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.status.StatusField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.text.TextField
import com.deiser.jira.profields.api.value.ValueService
@WithPlugin("com.deiser.jira.profields")
Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.getKey())
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
// You should use the StatusItemService to get the status item
def statusItemService = ComponentAccessor.getOSGiComponentInstanceOfType(StatusItemService.class)
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("KP");
def statusField = (StatusField)fieldService.get("9") //ID of field Status
log.warn(statusField.toString())
def karim = valueService.getValue(issue.projectObject,(StatusField) statusField)
log.warn(karim.toString())
// You need to get the existing status item with the text "rafix"
def newStatusItem = statusItemService.getItemByText((StatusField)statusField, "rafik")
// Call setValue(...) instead of setValues(...) and pass the status item as third parameter
valueService.setValue(project,(StatusField)statusField,newStatusItem)
Regards.
Hello Carlos
nice to meet you , i tried to to excute this code , but i stopped in this line ,
// You need to get the existing status item with the text "rafix"
def newStatusItem = statusItemService.getItemByText((StatusField)field, "rafik")
The error is [Static type checking] - The variable [field] is undeclared.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh sorry, change it to "statusField". I've modified the script in order to other people won't fall in the same error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.deiser.jira.profields.api.field.item.status.StatusItemService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.status.StatusField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.text.TextField
import com.deiser.jira.profields.api.value.ValueService
@WithPlugin("com.deiser.jira.profields")
Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.getKey())
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
// You should use the StatusItemService to get the status item
def statusItemService = ComponentAccessor.getOSGiComponentInstanceOfType(StatusItemService.class)
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("KP");
//return project.name
def statusField = (StatusField)fieldService.get(9)//ID of field Status
log.warn("statusField =" + statusField.name)
def statusvalue = valueService.getValue(issue.projectObject,(StatusField) statusField)
log.warn("value=" + statusvalue.toString())// Value of field Status
// YTheou need to get the existing status item with the text "EN COURS"
def newStatusItem = statusItemService.getItemByText((StatusField) statusField, "EN COURS")
// Call setValue(...) instead of setValues(...) and pass the status item as third parameter
valueService.setValue(project,(StatusField)statusField,newStatusItem)
When i excute this code in Console it work fine , and the statut field change , but when i make this code in a post function . Nothing happened. Can you please help me !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In which transition is the postfunction and the order between the other postfuncions?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I make it in The transition start progress
The order to my post function is 5.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i think the problem is in the issue key , but i dont know how to solve it .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you don't need this line, it's redundant:
Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey(issue.getKey())
You already have the issue in the context
The project "KP" is the current issue project?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i think that because now im executing my code in a script field , so i fix my issue to test on it , but when i left to post function script profields it dosen't work .
Have you other explication !
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As I edit the comment, probably you don't see this question: The project "KP" is the current issue project?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes the project KP is the current issue project. but in the other hand , i would like to get project by key or other thing , because i will use this post-function in many projects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, if you want to set the value in other project different than the issue project and you are in a postfunction, the script is like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.item.status.StatusItemService
import com.deiser.jira.profields.api.field.status.StatusField
import com.deiser.jira.profields.api.value.ValueService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
@WithPlugin("com.deiser.jira.profields")
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def statusItemService = ComponentAccessor.getOSGiComponentInstanceOfType(StatusItemService.class)
// Gets the issue project, is not used for anything
Project issueProject = issue.projectObject
// Gets other project
Project project = ComponentAccessor.projectManager.getProjectObjByKey("KP")
// Gets the status field
def statusField = (StatusField) fieldService.get(9)
// This line is not used for anything
def statusValue = valueService.getValue(issueProject, (StatusField) statusField)
// Gets the status item base on a text
def newStatusItem = statusItemService.getItemByText((StatusField) statusField, "EN COURS")
// Set the value in the "other" project
valueService.setValue(project, (StatusField) statusField, newStatusItem)
You can see that you don't use the issue for anything, only for get the status value in its project, but you don't make anything with this value. I comment it inline.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Carlos before passing to the project key , now im blocked because i can not excute this correct code in a post function !
Some solution to that.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Don't understand this:
before passing to the project key
And, why you can't execute the code in a postfunction? Any error?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Carlos can we organize a teamviwer session ! to explain to you my problem !!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well I can see you've created a ticket in our Jira, best we continue there
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
How I can get the ID of a profield field ?
Thanks a lot!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you go to Profields > Fields and you hover the name of any field, a tooltip is shown with the field's ID.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In this page we explain how to get the ID of a project field:
Regards,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@carlos_fernandez @Leo Diaz _ DEISER
Thanks a lot!
I've another question, Im tryng get the value from a GroupMultipleField, but the result only gives me this and not the value ... can you helpme?
[runner.AbstractScriptRunner]: Cel value: [com.atlassian.crowd.embedded.impl.ImmutableGroup@33916d5]
Here is my code:
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKeyIgnoreCase(pkey)
log.warn("project: "+project)
def CelField = fieldService.get(41)
def CelValue = valueService.getValue(project, (GroupMultipleField) CelField).toString()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The value of a GroupMultipleField is a list of Jira Group objects.
If you need to do something with each group you can do this:
CelValue.each{ group ->
// do something with the group
print(group.name)
}
If you need to print the values separated by commas, you can do this:
print CelValue.collect{group-> group.name}.join(", ")
Hope it helps
Regards
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.
@carlos_fernandez @Leo Diaz _ DEISER
Thanks a lot!
I have another question,
I will explain what I am doing:
I have a custom field where users enter the release, and from that field I want to complete another field with profield information.
From that release id I enter the project and with the project id I will look for the "profield" field, what is my problem? To validate all the possible release id and bring the "profield" field for each one of them, I must use a "FOR" which is not allowing me to save all the values ​​as one. Sorry if I don't explain myself well, thank you very much!
Here is my results and my code:
Results:
TEAM_TERMINAL_FINANCIERO
TEAM_OPTIMUS
Expected results:
TEAM_TERMINAL_FINANCIERO , TEAM_OPTIMUS
or
[TEAM_TERMINAL_FINANCIERO , TEAM_OPTIMUS ]
Here is the code:
@WithPlugin("com.deiser.jira.profields")
def ProjectManager = ComponentAccessor.projectManager
def VersionManager = ComponentAccessor.versionManager
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueObject("DPG-1189")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cf1 = customFieldManager.getCustomFieldObjects(issue).find {it.name =="Proyecto/Release"}
def cf1val = issue.getCustomFieldValue(cf1) as List
log.warn("el valor de Celula/Release es:"+cf1val)
List<Integer> listIntegers = new ArrayList<Integer>(cf1val.size());
for(String current:cf1val){
listIntegers.add(Integer.parseInt(current));
}
int nInts = listIntegers.size();
List<Long> longs = new ArrayList<Long>(nInts);
for (int i=0;i<nInts;++i) {
longs.add(listIntegers.get(i).longValue());
}
for (int i in longs )
{
def versionObject = VersionManager.getVersion(i)
def pid = versionObject.projectId
def p = ProjectManager.getProjectObj(pid)
def pkey = p.getKey()
log.warn("pkey: "+pkey)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKeyIgnoreCase(pkey)
log.warn("project: "+project)
def CelField = fieldService.get(41)
def CelValue = valueService.getValue(project, (GroupMultipleField) CelField)
//log.warn("Cel value: "+CelValue)
// CelValue.each{ group ->
//log.warn(group.name)
//}
log.warn("join: "+CelValue.collect{group-> group.name}.join(", "))
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can't see where do you try to save the value.
Please add this piece of code in order to understand the script.
Please, indicate the "type" of each Profields field and Jira custom fields to know what kind of values they store.
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@carlos_fernandez @Leo Diaz _ DEISER
Thank you very much for your prompt reply
This is a field in the issue where I will look for the release id.
CustomField cf1 in the code:
--->
This is the cell field, currently this field is manual and you can choose one or more of the values ​​it contains (for example: TEAM_KOMEX)
This field brings the same values ​​as the "Cell / s" field in profields, therefore this is where I want to save the value that I get from profields through the release id.
Currently I still do not implement it in the code since I still do not get the values ​​correctly from the profield field
--->
and this would be the profield field that I want to obtain and replicate in my issue field "Cells / s", it is of the type "group multple field" since it only brings groups in jira.
CelValue in the code.
To understand a little more the context of what is being done, the cell is the project work team, therefore we want to obtain that "cell" is working in "x" release
--->
so my idea is to save this result "CelValue.collect{group-> group.name}.join(", ")" in a variable to assign it to the issue field "Cell" as List.
But at the moment I am only rescuing one value of more possible in the "FOR loop"
I hope I have made myself understood well, thanks you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
in resume:
the problem its in CelValue.collect{group-> group.name}.join(", ")"
The join its not working :/ only shows one value
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.
Hi Ignacio!
I think we are dealing with a very specific issue, could you raise a ticket so we can give you better support?
Thanks!
Leo
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.
Show up and give back by attending an Atlassian Community Event: we’ll donate $10 for every event attendee in March!
Join an Atlassian Community Event!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.