Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

csv2testrail - Multi-select fields


#1

Hi guys!

I’ve written a conversion filter to go from the exported Excel files back to XML for import (updating in Excel is easier than XML as the XML elements aren’t exported if they are blank!), but I’m struggling to figure out how to create the arrays required for multi-select fields.

Normally we could do something like:

$custom['somefield'] = array('id' => $somedata);

But the expectation of the XML script is that each tag is inside it’s own element:

<test_tags>
<item>
<id>0</id>
</item>
<item>
<id>500</id>
</item>
</test_tags>

I have the ID’s figured out and mapped, so all that’s missing is the array structure. I’d greatly appreciate your help on this one :slight_smile:


#2

Hello Glenn,

Thanks for your posting. This structure would look as follows in PHP/the csv2testrail script:

$custom['test_tags'] = array('collection:item' => array( array('id' => 0), array('id' => 500) ) );

This can also be built dynamically by initializing it with an empty array and then adding items as needed:

$custom['test_tags'] = array('collection:item' => array()); $custom['test_tags']['collection:item'][] = array('id' => 0); $custom['test_tags']['collection:item'][] = array('id' => 500);

I hope this helps and please let me know in case you have any further questions.

Regards,
Tobias


#3

Thanks Tobias! The second option was perfect :slight_smile:


#4

Thanks for the update, Glenn. Great to hear that this works well for you :slight_smile: Just let me know in case there’s anything else I can help with and have a good weekend.

Regards,
Tobias