Skip to main content
1-Visitor
December 11, 2013
Solved

how do I set Transaction Context in triggers

  • December 11, 2013
  • 2 replies
  • 3394 views

There is a script command called getTransactionContext in the Server Bean. In the description, it mentions a map that can be used to pass information from one script to the next during a transaction. I cannot find how to set or add to this map however.

Would someone please let me know how to add to this map?

Thanks

Mark

    Best answer by mbohanon

    Hello everyone,

    I figured it out. After browsing one of the MKS_ALM scripts, I found this: sb.getTransactionContext().put("AutoLabel", "1");

    I was confused by the word "get" in getTransactionContext. You can add your own by using .put(key,value)

    2 replies

    1-Visitor
    January 21, 2014

    Mark,

    You are correct that there is little documentation provided regarding this method. There is an RFC in the system to provide better data for this here: Docs request for getTransactionContext method in the server bean

    Please contact PTC Integrity Support if you would like to be added to this RFC.

    In the meantime, I can give you some examples on how this may be used. This example applies to the document model context, but it might give you an idea of how it works.

    For document model operations, the context map will have the key "operation" set, with value = "<document model op>" where <document model op> can be

    one of:

    createcontent

    createsegment

    insertsegment

    movecontent

    removecontent

    branchsegment

    changesegmentproject

    refmode

    baseline

    removebaseline

    propagatetraces

    segmentroots

    geneology

    viewsegment

    togglereference

    documentedit

    For all other issue edits, there are no values in the context map.

    if operation=createsegment, two key/value pairs are added if there is a parent id:

    parent=<parentID>

    include=true|false

    if operation=insertsegment, one additional key/value pair is added:

    include=true|false

    e.g. if I run the command: im createsegment --insertMode=reference --parentID=971 --type="ALM_Input Document" --field=Project="/ALM_Projects/Release2" --field="ALM_Document Short Title"="test"

    then getTransactionContextMap will return:

    Key: operation Value: createsegment

    Key: parentid Value: 971

    Key: include Value: false

    mbohanon1-VisitorAuthor
    1-Visitor
    April 11, 2014

    Hello Jeremy,

    Is there any way to create a Key-Value pair? I was interested in having some method of passing information from one trigger to the next since delta beans don't know where they came from (other than Secondary Issue Change).

    1-Visitor
    April 15, 2014

    Mark,

    This is tricky as I'm not sure that we have a properties class or some kind of thread local storage that we can use to pass around data. What kind of info are you looking to share between triggers?

    mbohanon1-VisitorAuthorAnswer
    1-Visitor
    July 24, 2014

    Hello everyone,

    I figured it out. After browsing one of the MKS_ALM scripts, I found this: sb.getTransactionContext().put("AutoLabel", "1");

    I was confused by the word "get" in getTransactionContext. You can add your own by using .put(key,value)