Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner executing built-in scripts remotely

Paweł Łukowak
July 11, 2018

Hi team, i'm trying to run reindexing remotely via curl on linux. Following the example I created add-opt.json: 

{
"FIELD_FILTER_ID":"39864",
"FIELD_PROJECT_ID":"",
"FIELD_FUNCTION_ID":"",
"canned-script":"com.onresolve.scriptrunner.canned.jira.admin.ReindexIssues"
}

and executed command :

curl -u login:pass "https://jiraURL/rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.ReindexIssues" -H "X-Atlassian-token: no-check" -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json" --data "@add-opt.json"

 

The following works perfectly on both of our test servers, however it doesnt on main server. Error is: Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token\n at 

Jira ver 7.2.8

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
3 votes
Answer accepted
Carmen Creswell [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
May 10, 2018

Here is a script that will copy the values from a Custom Field into the Linked Issues' Custom Fields:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.issueLinkManager
def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def issue = issueManager.getIssueByCurrentKey('JRA-2') // change this to match your main issue key
def customField = customFieldManager.getCustomFieldObjectsByName('MultiSelectA')[0] // change this to match your custom field name

def customFieldValue = issue.getCustomFieldValue(customField)
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()

def linkedIssues = issueLinkManager.getLinkCollection(issue, currentUser).getAllIssues()

for (int i = 0; i < linkedIssues.size(); i++) {
log.debug("Updating issue: ${linkedIssues[i]}")

// This is for the Multi Select List. It will change if you work with another type of Custom Field
// For example, you won't have to loop through a text field, you would just pass what was in customFieldValue
def values = customFieldValue.collect{ Option option ->
option.optionId.toString()
}

issueInputParameters.with {
addCustomFieldValue(customField.idAsLong, *values) // *values is something Groovy does to destruct a list into plain arguments
}

def updateValidationResult = issueService.validateUpdate(currentUser, linkedIssues[i].id, issueInputParameters)

if (updateValidationResult.isValid()) {
def finalUpdateResult = issueService.update(currentUser, updateValidationResult)
log.debug(finalUpdateResult.errorCollection)
log.debug(finalUpdateResult.warningCollection.getWarnings())
log.debug(finalUpdateResult.isValid())
} else {
log.debug(updateValidationResult.errorCollection)
log.debug(updateValidationResult.warningCollection.getWarnings())
}

}
Deleted user
September 2, 2019

Hi,

the script works fine with multiselect fields, but how do I get it to work with Singe User Picker custom fields? 

best regards 

Anuradha Yadav
September 7, 2022

Hi @[deleted] ,

Have you found the solution for your question?

Can come one please help?

 

Regards,

Anuradha

Anuradha Yadav
September 11, 2022

Hi @Carmen Creswell [Adaptavist] 

Could you please help here?

 

Regards,

Anuradha

0 votes
Jiri Kanicky
November 11, 2018

@Avinashhave you been able to create the script?

I also need a script which copies Region field value from linked issue to Region field of the issue where the link was created.

Can you share it?

Avinash
Contributor
November 11, 2018

Hi @Jiri Kanicky 

Yes, What type of field in JIRA is region field value ? 

Jiri Kanicky
November 11, 2018

Hi. Its a Select List (single choice) custom field.

I have the following setup:

  • Project_Support
  • Project_Surveys

When I link Support ticket to Survey ticket (from Survey ticket), I need to pull the Support ticket Region field value and update the Survey ticket Region field value.

Thanks for your help.

0 votes
Kyle Moseley
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
March 7, 2018

I think your only reference to issue (the current issue, AB-1 or AB-2) is where you're assigning linkedTasks's initial value. That leads me to believe that there could be some sort of flaw in the logic. Are you sure AB-2 has the same direction of link at AB-1?

TAGS
AUG Leaders

Atlassian Community Events