Jump to content
  • Updating TIBCO® BPM tasks priority from Spotfire®


    Use Case

    User accesses the Spotfire® dashboard to monitor business processes activities. He identifies a selection of Tasks and updates their priority.

    Implementation

    This sample IronPython script can be used in a Spotfire dashboard

    # Script to invoke AMXBPM API to change workitem priorities
    # IMPORTANT ASSUMPTIONS
    #   AMXBPMenpoint property mus be defined to something like
    #    http://localhost:8080/bpm/rest
    #    the data table column with workitem ids is of type STRING !
    #    Credential is hardcoded to be tibco-admin:secret
    # Parameters
    #  markingName  : spotfire used to retrieve the workitem ids
    #  markingTable : data table used to retrieve the workitem ids
    #  columnName   : column in the data table having the workitem id as a string
    #  absPriority  : priority to be set
    #
    #
    #
    # import needed for Modal Dialog
    import clr
    clr.AddReference("System.Windows.Forms")
    from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions
    from System.Windows.Forms import DialogResult
    
    # import needed to use .Net WebRequest
    from System.Net import WebRequest
    from System.Text import Encoding
    
    # import needed to manipulate Marking
    from Spotfire.Dxp.Data import DataManager
    from Spotfire.Dxp.Data import IndexSet
    from Spotfire.Dxp.Data import RowSelection
    from Spotfire.Dxp.Data import DataValueCursor
    
    
    print("using marking : "+markingName+"")
    
    # build REST API URL using AMXBPMenpoint property
    url=Document.Properties["AMXBPMendpoint"]+"/workitem/setpriority";
    print("API URL : "+url);
    print("target priority : "+ str(absPriority));
    
    
    # Modal using System.Windows.Forms
    # MessageBoxOptions.ServiceNotification mandatory to get this code working in webplayer
    
    dialogResult = MessageBox.Show(
    "Confirm changing priority of selected tasks to "+str(absPriority),
    "Confirmation",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question,     
    MessageBoxDefaultButton.Button1,
    MessageBoxOptions.ServiceNotification);
    
    if(dialogResult == DialogResult.Yes):
       # prepare the web request and payload
       req=WebRequest.Create(url)
       req.Method='PUT'
       req.ContentType = "application/json"
       
       header=req.Headers
       header.Add("authorization","Basic dGliY28tYWRtaW46c2VjcmV0")
       header.Add("cache-control","no-cache")
       body=req.GetRequestStream()
       payload='{ "setWorkItemPriority": { "workItemIDandPriority": ['
       #
       # retrieve selection logic
       #
       marking=Application.GetService[DataManager]().Markings[markingName]
       selection = marking.GetSelection(markingTable)
       indexSet = selection.AsIndexSet()
       c1=DataValueCursor.Create[str](markingTable.Columns[columnName])
       for row in markingTable.GetRows(indexSet, c1):
           payload=payload+'{"workItemID": {"@id":"'+c1.CurrentValue+'"}, "workItemPriority": {"absPriority":"'+str(absPriority)+'"}},'
    
       # finish the JSON payload
       payload+=']}}'
       print(payload)
    
       # send the webRequest
       bodyBytes=Encoding.UTF8.GetBytes(payload)
       body.Write(bodyBytes,0,bodyBytes.Length)
       body.Close()
    
       # read the http response
       resp=req.GetResponse()
       print(resp.StatusCode)
    
       if (str(resp.StatusCode)=="OK"):
           MessageBox.Show("Requested change done.","Message",
    MessageBoxButtons.OK,
    MessageBoxIcon.Information,     
    MessageBoxDefaultButton.Button1,
    MessageBoxOptions.ServiceNotification);
    
           # force a refresh
           # note that WI_STATUS is populated asynchronously by the Event Collector
           # So the Refresh will probably don't work
           markingTable.Refresh()
       else:
           MessageBox.Show("Sorry can't make it. Error code "+str(resp.StatusCode),"Message",
    MessageBoxButtons.OK,
    MessageBoxIcon.Error,     
    MessageBoxDefaultButton.Button1,
    MessageBoxOptions.ServiceNotification);
    
    # END OF SCRIPT
     

    Usage

    You can add this script to the TIBCO ActiveMatrix® BPM 4.x Template provided with the product and add a textarea.

    Attachments

    Download from Resources.

    tibco_amxbpm_template_with_changepriority_script.dxp_.zip


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...