How To
How to update a Selection field definition via the RESTful API
when altering a swimlane application via the restful, use the put /app/id endpoint a common pitfall, when creating/altering selection fields within an app via code, is that the burden is on the client code to make sure that every value defined for a selection field must have a unique identifier the swimlane user guide doesn’t specify that such identifiers must be generated, and it does not give guidance on their proper form the code for generating the identifier can be found here this code will be included in the following sample illustrating how to fetch an existing application definition and alter an existing selection field the field's original values are “red”, “yellow”, and “blue” the snippet below removes the value “blue” and adds two others, “green” and “orange” from swimlane import swimlane import json import copy import time import binascii import os def random objectid() """returns a randomly generated mongodb objectid """ timestamp = '{0\ x}' format(int(time time())) rest = binascii b2a hex(os urandom(8)) decode('ascii') return timestamp + rest \# fetch the application's definition via the swimlane driver swimlane = swimlane('https //hostname', 'user', 'password', verify ssl=false) app = swimlane apps get(name='app name') \# fetch the selection field's definition and print its values, "red", "yellow", and "blue" selection field def = app get field definition by name('selection') \#print(json dumps(selection field def, sort keys=true, indent=4, separators=(",", " "))) \# find and remove "blue", and print to confirm success for field def in app raw\['fields'] 	if field def\['id'] == selection field def\['id'] 	 count = 0 	 for val in field def\['values'] 	 if val\['name'] == 'blue' 	 del field def\['values']\[count] 	 break 	 count += 1 print('blue has been removed\n\n') print(json dumps(app raw\['fields'], sort keys=true, indent=4, separators=(",", " "))) \# add two new values, and print to confirm success for field def in app raw\['fields'] 	if field def\['id'] == selection field def\['id'] 	 \# copy the structure of an existing value 	 new val green = copy deepcopy(field def\['values']\[0]) 	 new val green\['name'] = 'green' 	 new val green\['id'] = random objectid() 	 new val orange = copy deepcopy(field def\['values']\[0]) 	 new val orange\['name'] = 'orange' 	 new val orange\['id'] = random objectid() 	 field def\['values'] append(new val green) 	 field def\['values'] append(new val orange) 	 break print('orange and green have been added\n\n') print(json dumps(app raw\['fields'], sort keys=true, indent=4, separators=(",", " "))) \# finally, persist the field's alteration to the swimlane server, and print to confirm success resp = swimlane request( 'put', '/app/{0}' format(app id), json=app raw ) print str(resp status code) \#print resp text please note that when selection field definitions are altered, via the swimlane ui’s app build page or via client code, as shown above, problems can ensue that make it difficult to retrieve affected records via the swimlane driver