I have a Jython 2.7 script that receives a URL and uses the parameters/values in the URL to create or update records.
- Example URL:
http://server:host/maximo/oslc/script/CREATEWO?&wonum=WO0001&description=Legacy&classstructureid=1666&wopriority=1&worktype=CM
Details:
- Receive the URL and put the parameters/values in variables:
from psdi.server import MXServer from psdi.mbo import MboSet resp = {} wonum = request.getQueryParam("wonum") description = request.getQueryParam("description") classstructureid = request.getQueryParam("classstructureid") wopriority = request.getQueryParam("wopriority") worktype = request.getQueryParam("worktype")
- Some lines that aren't relevant to the question:
woset = MXServer.getMXServer().getMboSet("workorder",request.getUserInfo()) whereClause = "wonum= '" + wonum + "'" woset.setWhere(whereClause) woset.reset() woMbo = woset.moveFirst()
- Then use the values to either create a new record or update an existing record:
#If workorder already exists, update it: if woMbo is not None: woMbo.setValue("description", description) woMbo.setValue("classstructureid", classstructureid) woMbo.setValue("wopriority", wopriority) woMbo.setValue("worktype", worktype) woset.save() woset.clear() woset.close() resp[0]='Updated workorder ' + wonum #Else, create a new workorder else: woMbo=woset.add() woMbo.setValue("wonum",wonum) woMbo.setValue("description", description) woMbo.setValue("classstructureid", classstructureid) woMbo.setValue("wopriority", wopriority) woMbo.setValue("worktype", worktype) woset.save() woset.clear() woset.close() resp[0]='Created workorder ' + wonum responseBody =resp[0]
Question:
Unfortunately, the field names/values are hardcoded in 3 different places in the script.
I would like to enhance the script so that it is dynamic -- not hardcoded.
- In other words, it would be great if the script could accept a list of parameters/values and simply loop through them to update or create a record in the respective fields.
Is it possible to do this?