Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can update profield field value (status)

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")

 

 

 

 

 

 

 

2 answers

1 accepted

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.

Oh sorry, change it to "statusField". I've modified the script in order to other people won't fall in the same error.

Like Fede -DEISER- likes this

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 !

In which transition is the postfunction and the order between the other postfuncions?

I make it in The transition start progress 

The order to my post function is 5.

i think the problem is in the issue key , but i dont know how to solve it .

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?

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

As I edit the comment, probably you don't see this question: The project "KP" is the current issue project?

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.

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

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

Don't understand this:

before passing to the project key

 

And, why you can't execute the code in a postfunction? Any error?

Carlos can we organize a teamviwer session ! to explain to you my problem !!

Well I can see you've created a ticket in our Jira, best we continue there

@carlos_fernandez 

Hi! 

How I can get the ID of a profield field ?

Thanks a lot!

Hi @Ignacio Flores 

If you go to Profields > Fields and you hover the name of any field, a tooltip is shown with the field's ID.

Regards.

@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()

Hi @Ignacio Flores 

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

@carlos_fernandez @Leo Diaz _DEISER_ 

I tried what you mentioned, but I get the following:

 

java.png

@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(", "))


}

Hi @Ignacio Flores 

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

@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:

--->

RELEASE_FIELD.png

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

 

--->

CELULA_FIELD.png

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

 

--->

PROFIELD_FIELD.png

 

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!

in resume:

the problem its in CelValue.collect{group-> group.name}.join(", ")" 

The join its not working :/ only shows one value

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

@Karim Belhadj - Is this issue resolved. I am also facing the same issue.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

385 views 5 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you