Veracity Q&A home login about faq

Is there a way of exporting a list of work items as a normal text file, so I can print them out or load them into another software to create xustomized reports?

asked Jan 27 at 07:19

Grey's gravatar image

Grey
1263813

This is certainly possible with vscript. Details to follow, hopefully today...

(Jan 27 at 08:50) Ian Olsen ♦♦

Excellent, I look forward to it!

Thanks for the swift replies to all my questions today, btw. :)

(Jan 27 at 09:15) Grey

It would also be great to have a two-way technique, so you can export to a text file, and import that same text file back in to add other (possibly modified) work items.

(Feb 01 at 04:19) Grey

On the importing side, you might want to look at a blog post from last year, Adding Veracity Work Items via todo.txt and the script linked from there; it's more elaborate and specific than you'd want, but the core ideas are there.

A simple export script based on that follows, which you would run either as:

vscript listitems.js reponame

to list all items in the current milestone (if any is set), or

vscript listitems.js reponame milestone

to list all items from a specific milestone.

The output is tab-delimited to avoid having to escape commas.

// For entertainment purposes only. No warranty expressed or implied. Please, no wagering.

if ((arguments.length < 1) || (arguments.length > 2))
    showUsage();

var reponame = arguments[0];
var repo = null;
var milestone = null;

try
{
    repo = sg.open_repo(reponame);
}
catch (e)
{
    showUsage("Unable to open repo " + reponame + ": " + e.message);
}

if (arguments.length == 2)
    milestone = lookupMilestone(repo, arguments[1]);
else
    milestone = getCurrentMilestone(repo);

listTasks(repo, milestone);

repo.close();

quit(0);

function listTasks(repo, milestone)
{
    var users = {};

    var db = new zingdb(repo, sg.dagnum.USERS);
    var recs = db.query('user', ['*']);

    for ( var i = 0; i < recs.length; ++i )
        users[ recs[i].recid ] = recs[i].name;

    var useridToName = function(rec, field) {
        if (rec[field])
            rec[field] = users[ rec[field] ] || rec[field];
    };

    db = new zingdb(repo, sg.dagnum.WORK_ITEMS);

    recs = db.query('item', ['*'], "milestone == '" + milestone + "'");

    var fields = ['id', 'title', 'description', 'assignee', 'reporter', 'verifier', 'status', 'priority'];

    print( fields.join("\t") );

    for ( i = 0; i < recs.length; ++i )
    {
        var rec = recs[i];
        useridToName(rec, 'assignee');
        useridToName(rec, 'reporter');
        useridToName(rec, 'verifier');

        var vals = [];

        for ( var j = 0; j < fields.length; ++j )
        {
            var val = rec[ fields[j] ] || "";

            // keep everything on one line
            val = val.replace("\t", " ");
            val = val.replace(/^[ \t\r\n]+/, '');
            val = val.replace(/[ \t\r\n]+$/, '');
            val = val.replace(/\r?\n/g, "\\n");

            vals.push(val);
        }

        print( vals.join("\t") );
    }
}

// do we have a current milestone configured?
function getCurrentMilestone(repo)
{
    var cfg = new Configuration(repo);
    var cs = cfg.get('current_sprint');

    if (cs && cs.value)
        return(cs.value);

    showUsage("No milestone specified and no current milestone set");
}

function lookupMilestone(repo, milestone)
{
    var db = new zingdb(repo, sg.dagnum.WORK_ITEMS);
    var recs = db.query('sprint', ['recid'], "name == '" + milestone + "'");

    if ((! recs) || (recs.length == 0))
        showUsage("No milestone found matching '" + milestone + "'");

    return( recs[0].recid );
}

function showUsage(msg)
{
    if (repo)
        repo.close();

    if (msg)
    {
        msg = msg.replace(/[\r\n].+/, '') + "\n";   // trim stack trace
        print(msg);
    }

    print("usage: vscript listitems.js reponame [milestone]");

    quit(1);
}
link

answered Feb 02 at 08:56

Paul%20Roub's gravatar image

Paul Roub ♦♦
1.6k81141

Works like a dream. Thanks!

(Feb 07 at 11:47) Grey
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10
×4

Asked: Jan 27 at 07:19

Seen: 246 times

Last updated: Feb 07 at 11:47

powered by OSQA