How to set nFeed customfield programatically

3layer (expert) March 5, 2013

Hi all,

We are working in a JIRA replication project, where two remote instances should be continously synchronized.

Then, I need to set a nFeed customfield in a post-function using a Groovy code.

I am using a code like this, but does not work, raising the error below:

customerValue = "ABC CONS MET ASSES E MERC S/A - SAO PAULO - BRAZIL" //Sample value
cfCustomer = customFieldManager.getCustomFieldObject(10601) //nFeed Customer field
cfCustomer.updateValue(null, missue, new ModifiedValue(null, customerValue ), new DefaultIssueChangeHolder())

The error raised is:

2013-03-06 09:15:30,744 http-bio-9081-exec-9 ERROR 2208.1 555x25241x1 i8yokm 200.150.176.119,127.0.0.1 /secure/QuickCreateIssue.jspa [plugins.sql.customfield.SQLFeedCustomFieldType] Unexpected value 'ABC CONS MET ASSES E MERC S/A - SAO PAULO - BRAZIL'
2013-03-06 09:15:30,745 http-bio-9081-exec-9 ERROR 2208.1 555x25241x1 i8yokm 200.150.176.119,127.0.0.1 /secure/QuickCreateIssue.jspa [plugins.sql.customfield.SQLFeedCustomFieldType] Invalid data type 'ABC CONS MET ASSES E MERC S/A - SAO PAULO - BRAZIL' while creating changelog string


I think this very strange, since this value is exactly the same used where the field is showed in the issue view.

We tried use the primary key in the "customerValue" (like 1234), but the error remains.

There are some documentation or tip about this issue ?

2 answers

1 accepted

0 votes
Answer accepted
3layer (expert) March 6, 2013

Hi all, with support of Valiantys (https://jira.valiantys.com/browse/SQLFEED-521) the solution is:

customerValue = "ABC CONS MET ASSES E MERC S/A - SAO PAULO - BRAZIL" //Sample value
cfCustomer = customFieldManager.getCustomFieldObject(10601) //nFeed Customer field
nFeedContent = missue.getCustomFieldValue(cfCustomer)
nFeedContent.clear()
nFeedContent.add(customerValue)

cfCustomer.updateValue(null, missue, new ModifiedValue(null, customerValue ), new DefaultIssueChangeHolder())

0 votes
Nicolas Esteves November 16, 2018

Hello,

Here is a most updated answer:

import com.atlassian.jira.component.ComponentAccessor

def pluginAccessor = ComponentAccessor.getPluginAccessor();
def plugin = pluginAccessor.getPlugin("com.valiantys.jira.plugins.SQLFeed");
def serviceClass = plugin.getClassLoader().loadClass("com.valiantys.nfeed.api.IFieldValueService");

def fieldValueService = ComponentAccessor.getOSGiComponentInstanceOfType(serviceClass);

def issueKey = "ISSUE-12345";
def customFieldId = "customfield_12345";
def nFeedKeyValue = "10001";

fieldValueService.setFieldValue(issueKey, customFieldId, nFeedKeyValue);

 (i) If you need to read a value from an nFeed field, you can use the "getFieldValues(issueKey, customFieldId)" function from the same service.

Sources:

Kind regards,

Nicolas.

Vineela Durbha February 6, 2019

Hi Nicolas,

If we want to get nFeedKeyValue  programatically  ,can we use getFieldValues(issueKey, customFieldId) method? 

If so can we pass that value into setFieldValue method as a part of nfeedkeyvalue parameter?

Nicolas Esteves February 6, 2019

Hello Vineela,

Yes, you can use the getFieldValues function to get the Key of an nFeed custom field, against one of your issue.

For the second question, let me do a quick reminder of the service:

public interface IFieldValueService {
void setFieldValue(String issueKey, String customFieldId, Object fieldValue);
     void setFieldValues(String issueKey, String customFieldId, Collection<?> fieldValues);
     Collection<?> getFieldValues(String issueKey, String customFieldId);
}

As you can see, the getFieldValues function returns a Collection. So, if you want to use it as Key for another nFeed custom field, make sure your fields is a multiple values. The function to use in this case is: setFieldValues

Otherwise, you should use the other function, setFieldValue, and you need to extract the value from your Collection before, in order to pass it as a parameter.

Regards,

Vineela Durbha February 6, 2019

Thanks Nicolas

So is my below syntax correct?

Collection<?> collection=fieldValueService.getFieldValues(issue.getKey(),plannedrelos.getId())

Now I should be extracting the values from this collection rite?

Vineela Durbha February 6, 2019

Also when I try to pass this collection in setFieldvalues

fieldValueService.setFieldValue(issue.key,plannedrelos.getId(),coll

nothing is being set on nfeed field

Nicolas Esteves February 7, 2019

As answered in the support ticket:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category

Category log = log
log.setLevel(org.apache.log4j.Level.DEBUG)

def issueService = ComponentAccessor.getIssueService()
def issueManager = ComponentAccessor.getIssueManager()
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters.setSummary("TEST TEST")
issueInputParameters.setProjectId(10000L)
issueInputParameters.setIssueTypeId("10100")
issueInputParameters.setReporterId("valiantys")

def mySourceIssue = issueManager.getIssueObject("TEST-5")
def myField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10203")
def values = mySourceIssue.getCustomFieldValue(myField)

def String[] myArgs = new String[values.size()]
for (int i = 0; i < values.size(); i++) {
    myArgs[i] = values[i]
}

issueInputParameters.addCustomFieldValue((Long) 10203, myArgs)

def createValidationResult = issueService.validateCreate(loggedInUser, issueInputParameters)

if (createValidationResult.isValid())
{
    def createResult = issueService.create(loggedInUser, createValidationResult)
}else{
    log.debug("KO")
}
Graham Twine June 12, 2019

How would one do this if there is no issue key. 

 

i.e. when creating an issue and using the field in a scriptrunner field behavior?

def modifiedList = ['a', 'b']
getFieldByName("My List of Options").setFormValue(modifiedList)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events