Create the script, sigoption, select action and messages(use the ids in the script or update the script) and test. You also update the saved query description value in the script as per your requirement.
Working code:
from psdi.server import MXServer
mxServer=MXServer.getMXServer()
def createUniqueQueryParamList(listToBeUsed):
unique_list = []
for x in listToBeUsed:
if x not in unique_list:
unique_list.append(x)
return unique_list
userSession=service.webclientsession()
listSet=userSession.getCurrentApp().getResultsBean().getMboSet()
selectedSet=listSet.getSelection()
elements = selectedSet.elements()
selectedSiteList=[]
selectWOList=[]
while(elements.hasMoreElements()):
mbo=elements.nextElement()
selectedSiteList.append(mbo.getString("SITEID"))
selectWOList.append(mbo.getString("WONUM"))
uniqueSiteList=createUniqueQueryParamList(selectedSiteList)
uniqueWOList=createUniqueQueryParamList(selectWOList)
if len(uniqueSiteList)>0:
siteQuery="','".join(uniqueSiteList)
if len(uniqueWOList)>0:
workorderQuery="','".join(uniqueWOList)
if (siteQuery and workorderQuery):
#selectionWhereClause=listSet.getSelectionWhere()
selectionWhereClause=("SITEID in ('"+siteQuery+"') and wonum in ('"+workorderQuery+"')")
userid=mbo.getUserInfo().getLoginUserName()
querySet=mxServer.getMboSet("QUERY",mxServer.getSystemUserInfo())
querySet.setWhere("APP='WORKMAN' and OWNER='"+userid+"'")
querySet.reset()
query=querySet.getMbo(0)
if query is not None:
query.setValue("CLAUSE",selectionWhereClause,2L)
querySet.save()
else:
newQuery=querySet.add()
newQuery.setValue("OWNER",userid,2L)
newQuery.setValue("APP",'WORKMAN',2L)
newQuery.setValue("CLAUSENAME",userid+'WORKMAN',2L)
newQuery.setValue("ISPUBLIC",False,2L)
newQuery.setValue("CLAUSE",selectionWhereClause,2L)
newQuery.setValue("DESCRIPTION",userid+": Work Order tracking query",2L)
querySet.save()
userSession.showMessageBox("workorder", "queryCreated",[]);
else:
newQuery=querySet.add()
newQuery.setValue("OWNER",userid,2L)
newQuery.setValue("APP",'WORKMAN',2L)
newQuery.setValue("CLAUSENAME",userid+'WORKMAN',2L)
newQuery.setValue("ISPUBLIC",False,2L)
newQuery.setValue("CLAUSE",selectionWhereClause,2L)
newQuery.setValue("DESCRIPTION",userid+": Work Order tracking query",2L)
querySet.save()
userSession.showMessageBox("workorder", "queryCreated",[]);
else:
userSession.showMessageBox("workorder", "noRecord",[]);