How to set nFeed customfield programatically

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
Accepted answer

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

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.

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?

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,

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?

Also when I try to pass this collection in setFieldvalues

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

nothing is being set on nfeed field

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

446 views 8 26
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you