Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

row.put for customfield

josh wallace August 22, 2016

I've searched high and low for a solution to this problem but I can't seem to figure it out. I have a table with three columns. Sku, Quantity, RootCauses. RootCauses is linked to a customfield, a drop down list - pick one option.

I have attached a small piece of what I am trying to do. Basically put values into all three rows. I have no problem putting data into sku and quantity but because rootcauses is pulling from a custom field I can't seem to pick a value or choose an option.

I get: Grid ID=21363 content before modification: [[issueId:336261, quantity:123.0, RootCauses:[name:PO Flip, value:PO Flip], modified:1, id:11, sku:123]] Grid ID=21363 data cannot be added: List value '

{name=PO Flip, value=PO Flip}

' cannot be resolved for column 'RootCauses' Grid ID=21363 content after modification: [[issueId:336261, quantity:123.0, RootCauses:[name:PO Flip, value:PO Flip], modified:1, id:11, sku:123]]

I've tried it a couple different ways. I thought griddatamanager pulls the data as a hashmap so when you add a row you have to insert it as a hashmap but that doesn't seem to be the case.

How do I insert a value into a field that is linked to a customfield. For example one of the values in the customfield is PO Flip?

Thank You!

P.S We are currently testing your plugin, your documentation has been excellent so far.

 

 

Code:

import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.plugin.PluginAccessor;
import com.atlassian.jira.user.ApplicationUser;

// get an issue
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class);
Issue issue = issueManager.getIssueObject("SDSEA-224861");

// get TGE custom field
CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class);
CustomField tgeCustomField = customFieldManager.getCustomFieldObjectsByName("FC SKU and Quantity Variance").get(0);
Long tgeCustomFieldId = tgeCustomField.getIdAsLong();

// get current user
JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getOSGiComponentInstanceOfType(JiraAuthenticationContext.class);
Object userObject = jiraAuthenticationContext.getLoggedInUser();
User user = userObject instanceof ApplicationUser ? ((ApplicationUser) userObject).getDirectoryUser() : (User) userObject;

// read grid data
PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.TGEGridTableDataManager");
def tgeGridDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass);

StringBuilder result = new StringBuilder();
def callResult = null;
try {
    callResult = tgeGridDataManager.readGridData(issue.getId(), tgeCustomFieldId, null, null, 0, 10, user);
    result.append("Grid ID=" + tgeCustomFieldId + " content before modification: " + callResult.getValues() + "\n");
} catch (Exception e) {
    result.append("Grid ID=" + tgeCustomFieldId + " data cannot be retrieved: " + e.getMessage() + "\n");
}

def RootCauses = [name:'PO Flip', value:'PO Flip']

// let's add some rows
Map<String, Object> row = new HashMap<String, Object>();
row.put("sku", "123");
row.put("quantity", "123");
row.put("RootCauses", RootCauses);

try {
    List<Long> rowIds = tgeGridDataManager.addRows(issue.getId(), tgeCustomFieldId, Arrays.asList(row), user);
    result.append("Grid ID=" + tgeCustomFieldId + " data was successfully added. IDs of added rows: " + rowIds + "\n");
} catch (Exception e) {
    result.append("Grid ID=" + tgeCustomFieldId + " data cannot be added: " + e.getMessage() + "\n");
}

// check if data was really added
try {
    callResult = tgeGridDataManager.readGridData(issue.getId(), tgeCustomFieldId, null, null, 0, 10, user);
    result.append("Grid ID=" + tgeCustomFieldId + " content after modification: " + callResult.getValues() + "\n");
} catch (Exception e) {
    result.append("Grid ID=" + tgeCustomFieldId + " data cannot be retrieved: " + e.getMessage() + "\n");
}

println(result.toString());
return result.toString();

 

 

 

 

3 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 23, 2016

Here is the detail

 

Hi Joshua!
Use ID or Name of the list item as a list column value. Like it is done with "istatus" list column in original code sample.

Map<String, Object> row = new HashMap<String, Object>();
row.put("sku", "123");
row.put("quantity", "123");
row.put("RootCauses", "PO Flip");

We thought about using map as expected value for list column, but refused such approach. The key feature of list columns is restricted range of values that can be selected. Thus we need to resolve any passed value with some of the allowed list values. If we allowed user to pass a map with ID and Name it would lead to ambiguity: we should use either ID or Name to find a match. So it was decided to allow only plain value to be passed. It first will be matched with allowed list items' IDs, if no match was found - with items' Names.

Michael

0 votes
josh wallace August 23, 2016

Your solution in my support ticket worked. Feel free to publish it here and I'll give it my stamp of approval.

0 votes
francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
August 22, 2016

Hi Josh,

 

Is it ok to continue the conversation in the support ticket you raised, and then publish the answer in this thread afterwards ?

 

Francis

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events