Search code examples
pythonversionone

How to add a External source link to a versionone asset (TASK) through Python SDK


We are creating a customization where we would like to link every code related TASK to a bug.

My Plan is to check a task for category "Code" and check if it has a bug in bugtracking system. If not we will create a bug in bug tracking system and attach it to the TASK as below

 Reference = BugId 
Source = Bugzilla
link = task.Links.first() link.url = "Bug tracking url"

So here lies the problem, through Python SDK, what is the function to be called to create a Link which should get attached to the TASK and have the url of the bug tracking system in the URL attribute.

When I next query for Links in the corresponding task asset I should be able to fetch the bug tracking URL through

task.Links[0].URL


Solution

  • The way to achieve it is to create a link and attach the asset to the asset property of the link

    For Ex: v1 is an instacnce of V1Meta package from v1pysdk

    asset = v1.asset_from_oid('Task:2209')
    taskSource = v1.TaskSource.where(Name="Bugzilla").first()
    

    Now create a link like below

    new_link = v1.Link.create(
                Name="Bugzilla",
                URL="{0}".format(newbug.weburl),
                OnMenu="true",
                Asset=asset
    )
    asset.Source=taskSource
    v1.commit()
    

    Above code will create a link and the link is attached to the asset