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

How can I parse data from a custom field that uses XML tags in my script?

Cole
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 Leaders.
March 6, 2017

I am using an addon, called nFeed, that makes a new kind of field and the field is wrapped in XML tags. Because of this I have not been able to use them appropriately in my script post functions.

My script looks at a certain field to see the value and then sets a cascading field based on it.

Script:

if (issue.get("customfield_18784") == "Olathe Service Desk"){
def optionsManager = ComponentAccessor.getOptionsManager();
def parentOptionObj = optionsManager.findByOptionId(19044);
def childOptionObj = optionsManager.findByOptionId(19062);
Map<String,Object> newValues = new HashMap<String, String>();
newValues.put(null, parentOptionObj);
newValues.put("1", childOptionObj);
return newValues;
}

This script does not work because of the XML tags. The value of the field looks like this with tags:

[ <content>
<value>Olathe Service Desk</value>
</content> ]

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Christophe Promé November 3, 2017

Hi Cole,

Since version 5.12, nFeed exposes a Java API that can be used to get fields display value and set/get fields key.

Please, have a look at the documentation for more info:

https://valiantys.atlassian.net/wiki/spaces/NFEED512X/pages/99942724/Java+API

https://valiantys.atlassian.net/wiki/spaces/NFEED512X/pages/99942587/How+to+obtain+a+nFeed+custom+field+display+in+a+scripted+field

Regards

Christophe

0 votes
David _old account_
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 Leaders.
March 6, 2017

I believe the developer of nFeed is currently working on this. In the meantime, they recommend using the "deprecated" field types. see https://valiantys.atlassian.net/browse/NFEED-2040.

Otherwise, you could try parsing the XML with a simple regexp - or just comparing to the full XML string. You should also make sure the value is not an array of strings (based on the square brackets you showed in your example), in which case you need to iterate over the array.

TAGS
AUG Leaders

Atlassian Community Events