Set a custom field using webservice, python

Description
stoejs
Posts: 6
Joined: Wed Jan 24, 2018 12:05 pm

Set a custom field using webservice, python

Postby stoejs » Wed Oct 24, 2018 12:13 pm

Hi,
I'm trying to fill a custom field 'changes', which is a rich text box just as Description, returned as follows by getCustomFieldTypes:

Code: Select all

{
    'defaultValue': None,
    'dependsOn': None,
    'description': None,
    'id': 'changes',
    'multi': False,
    'name': 'Changes',
    'required': False,
    'type': 'ns19:Text'
}

When I read a workitem with filled in changes, I get

Code: Select all

{
'key': 'changes',
'value': {
    'type': 'text/html',
    'content': 'test content',
    'contentLossy': False
    }
}


The code I'm using:

Code: Select all

# create a 'container', I do that when I build work items as well
changes_template = tracker_client.get_type('ns2:CustomField')
# fill it with conent
changes_field = changes_template(
    key='changes',
    parentItemURI=self.wi.uri,
    value={
       'type': 'ns19:Text',
        'content': 'test content',
        'contentLossy': False
        }
    )
self.tracker.setCustomField(changes_field)


Running it results in

Code: Select all

java.lang.IllegalArgumentException: type cannot be null


Code: Select all

>>> print(changes_field)
{
    'key': 'changes',
    'parentItemURI': 'subterra:data-service:objects:/default/PROJECTID${WorkItem}PREFIX-2353',
    'value': {
        'type': 'ns19:Text',
        'content': 'testy test test',
        'contentLossy': False
    }
}

So I'm guessing the custom field does not get built correctly. Any advice on how to work on that?

stoejs
Posts: 6
Joined: Wed Jan 24, 2018 12:05 pm

Re: Set a custom field using webservice, python

Postby stoejs » Tue Jan 22, 2019 12:30 pm

So I figured it out:

Code: Select all

## Filling the custom field 'changes' with content
## tracker_client is created a zeep Client
## wi is an instance of a custom Workitem class, created just like the ones below

# Create a callable text creator
text_type = tracker_client.get_type('ns1:Text')
# create a text object
txt = text_type('text/html', content='This is a content string<br/>', contentLossy=False)
# Create a callable custom field creator
changes_type = tracker_client.get_type('ns2:CustomField')
# create a custom field object
changes = changes_type(key='changes', parentItemURI=self.wi.uri, value=txt)
self.wi.customFields['Custom'].append(changes)


Return to “Polarion Application Lifecycle Management (ALM)”

Who is online

Users browsing this forum: No registered users and 7 guests