Rally Software

  • 1.  pyral method to return epics and stories returns objects for some fields

    Posted Apr 19, 2017 12:57 PM

    I get reference to objects when attempting to use Pyral to export rally records to a csv.  How do I get to the data contained in the objects?

     

    US69 None  [] User Story Maggie-1  <pyral.entity.HierarchicalRequirement object at 0x00000000047A54A8> [] <pyral.entity.User object at 0x000000000529C320> None

     

    I want to get the data from the User object, the Feature object and Tags and such.

     

    Here is my code.

    def getUserStories2():
        response = rally.get("HierarchicalRequirement", fetch=True, pagesize=200, limit = 50)
        rally.enableLogging('path to logs pyral.log')
        try:
            for item in response:
                foid = item.FormattedID
                cdr = item.c_ContentDevReviewRequired
                desc = item.Description
                tags = item.Tags
                name = item.Name
                notes = item.Notes
                parent = item.Parent
                children = item.Children
                owner = item.Owner
                feid = item.PortfolioItem
                #state = item.Name.state
                #print item.details()
                #total = len(response)
                print foid, cdr, desc, tags, name, notes,  parent, children, owner ,feid #state, feature, tags, parent, owner
        except Exception, details:
            sys.stderr.write('ERROR: %s \n' % details)
            sys.exit(1)

    Output:
    US69 None [] User Story 1 <pyral.entity.HierarchicalRequirement object at 0x00000000047A54A8> [] <pyral.entity.User object at 0x000000000529C320> None
    US70 None [] User Story 2 None [<pyral.entity.HierarchicalRequirement object at 0x00000000047A54A8>, <pyral.entity.HierarchicalRequirement object at 0x00000000047A5320>] <pyral.entity.User object at 0x00000000050FC9E8> None
    US71 None [] User Story 3 None [] <pyral.entity.User object at 0x00000000050FCE10> None#####


  • 2.  Re: pyral method to return epics and stories returns objects for some fields

    Posted Apr 19, 2017 05:04 PM

    Hi Malcom,

     

    If the Object is a One to One relation ship you can simply use the variable assigned to the Object in question. If it is a One-to-Many relationship (A collection) you can then loop through that Object variable to get specific values. Here is a very quick and simple example:

     

    query_criteria = 'FormattedID contains "%s"' % args[0]

    print(query_criteria)

    response = rally.get('HierarchicalRequirement', fetch=True, query=query_criteria)

    if response.errors:

        sys.stdout.write("\n".join(errors))

        sys.exit(1)

    for us in response: 

      children=us.Children

      print  'Here is Parent User Story Name:'

      print  us.Name

      for child in children:

        print 'Here is a child User Story:'

        print child.FormattedID

     

    Let me know if that helps.

     

    Thanks,

    Sean Davis



  • 3.  Re: pyral method to return epics and stories returns objects for some fields
    Best Answer

    Posted Apr 24, 2017 10:42 PM

    Thanks Sean,

     

    That was helpful.  I was able to get all the fields with the exception of the Tags and Feature ID.  Here is my modified code. for those.

     

    response = rally.get("HierarchicalRequirement", fetch=True, pagesize=200, limit=20# , limit=5
    rally.enableLogging('C:\\Users\\malcolmc\\Documents\\Projects\\Migration\\DataDump\\pyral.log')
    try:
        for item in response:
            for tag in tags:
            mytags = []
            tags = item.Tags  <--Should this be item.Tags.something?  I tried Tag which I find in the API docs but it didn't work.  Got an error.
                mytags.append(tag)  <---Idea is to write tags content into a mytags[] list.  Still results in an object.
            try:
                feid = ''
                feid = item.PortfolioItem.Feature.description  <---Can't seem to find the right PortfolioItem attribute.  I think I'm close, just haven't found the right one yet.
            except StandardError:
                if feid is None:
                    print "No Feature associated with this issue."


    Thanks,

    Malcolm       

      


  • 4.  Re: pyral method to return epics and stories returns objects for some fields

    Posted Apr 28, 2017 02:31 PM

    Hello, 

    I've isolated the two outputs to the ones that don't work.  "Tags" and Feature.  Anyone know what I'm doing wrong on "Tags" and "Feature".  Any insight would be greatly appreciated.

    def getuserstories():
        response = rally.get("HierarchicalRequirement", fetch=True, pagesize=200, limit=10
        rally.enableLogging('C:\\Users\\malcolmc\\Documents\\Projects\\Migration\\DataDump\\pyral.log')
        try:
            for item in response:
                mytags = []
                tags = item.Tags
                for tag in tags:  <-----Seems like looping through the object should work but it's not.
                   mytags.append(tag)
                feid = ''
                try:
                    feid = item.PortfolioItem.FormattedID  <------This does not return the "Feature" data.  returns as empty, even for records that have Features.
                except StandardError:
                    if feid is None:
                        pass
               
                fields2 = (mytags, feid)
                print fields2
        except Exception, details:
            sys.stderr.write('ERROR: %s \n' % details)
            sys.exit(1)

    Output:

    ([], '')
    ([], '')
    ([], '')
    ([<pyral.entity.Tag object at 0x000000000558DF60>], '')  <---  The tag object is being returned instead of data.  The feature is empty but shouldn't be.
    ([<pyral.entity.Tag object at 0x0000000005755438>], '')
    ([<pyral.entity.Tag object at 0x0000000004BB31D0>], '')
    ([<pyral.entity.Tag object at 0x0000000005755390>], '')
    ([<pyral.entity.Tag object at 0x0000000005755400>], '')
    ([<pyral.entity.Tag object at 0x0000000004BB3278>], '')
    ([<pyral.entity.Tag object at 0x000000000558DF28>], '')