How to: Add/Remove Digital.ai Release Task Variables from User Input Tasks using Jython API

Scenario

You have a few Digital.ai Release variables and you want to add or remove  User Input Tasks using Jython API from within a Jython Script task.

Environment

Digital.ai Release

Steps to Follow

  1. Create your Digital.ai Release Variables. This can be done manually or using Jython API from within a Jython script task.
  2. Create two user Input tasks A and B. This can, again, be done manually or using Jython API. Our example script does everything automatically.
  3. Below are scripts you can use to add/remove Task variables. We added relevant comments to make the script more descriptive.
#Creating 3 Release variables first.
print "Creating a Release variable userName... \n"
myvar = Variable('userName', 'shashank')
myvar.setLabel("userName")
releaseApi.createVariable(release.id, myvar)
var_userName = releaseApi.getVariables(release.id)
print "Below is newly created variable. \n"
print var_userName

print "\n Creating a Release variable passWord... \n"
myvar2 = Variable('passWord', 'password')
myvar2.setLabel("passWord")
releaseApi.createVariable(release.id, myvar2)
varList = releaseApi.getVariables(release.id)
var_passWord = varList[1]
print "Below is newly created variable. \n"
print var_passWord

print "\n Creating another Release variable hostName... \n"
myvar3 = Variable('hostName', 'mysql-server')
myvar3.setLabel("hostName")
releaseApi.createVariable(release.id, myvar3)
varList = releaseApi.getVariables(release.id)
print "Printing Variables list... \n"
print varList
print "\n"
var_hostName = varList[2]
print "Below is newly created variable. \n"
print var_hostName

#Creating a User Input task & adding variables to it from Release variables.
print "\n Creating a User Input task A... \n"
phase = getCurrentPhase()
task = taskApi.newTask("xlrelease.UserInputTask")
task.title = "User Input task A"
task.setVariables(varList)
taskApi.addTask(phase.id, task)
print "User Input task created. \n"

#Creating a User Input task, adding variables to it from Release variables & then
removing the 3rd variable var_hostName.
print "\n Creating a User Input task B... \n"
phase = getCurrentPhase()
task2 = taskApi.newTask("xlrelease.UserInputTask")
task2.title = "User Input task B"
task2.setVariables(varList)
taskApi.addTask(phase.id, task2)
print "User Input task2 created. \n"
print "Printing User Input task Variables...\n"
print task2.variables
print "\n Removing User Input task variable %s" % var_hostName.getLabel()
print "\n"
task2.variables = [x for x in task2.variables if x.id != var_hostName.id]
taskApi.updateTask(task2)
print "Variable removed from 2nd User Input task."

 

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.