Combine the value from two response fields in a third field

rampramp Posts: 4


I am writing a SOAP Message Responder. Some of the fields of the response derives its value from a DataSource column while some gets their value from variables populated by an XML Data Bank.

Now my question is how do I combine these values to populate another field in the response. For example, I need a field to be the product of a field that derives its value from a datasource and another field that derives its value from a variable.



  • OmarROmarR Posts: 176 admin
    edited December 2016

    Our first Post! Welcome ramp!
    To clarify, are you asking how to parameterize an xml databank value AND a datasource (table, repo, file, etc) in your response? If so, you have the ability to select between the two when in Form Input/ Form XML mode. You may also parameterize the value by using the ${} syntax in Literal mode.

    If you wish to concatenate values from an xml databank and a datasource for a field in your response, you can use an xml databank or an xml transformer to ALTER the specific field and APPEND the value to the already parameterized field.

    Alternatively, you can achieve this by using the ${} syntax. For example: ${Table_Data}${Databank_value}

  • rampramp Posts: 4

    Thank you for your response. I want to implement a product (multiplication rather than concatenation). So I should be able to ${Table_Data} * ${Databank_value} in a literal mode? I don't have access to my dev environment right now. I will try it out and let you know how it worked.

  • Chris ColosimoChris Colosimo Posts: 65 admin
    edited December 2016

    Hi Ram,

    To accomplish the multiplication you will need to script the response for the element. 1. You can select the "scripted" option from the element that you wish to recieve the combined result

    1. Enter a script like this. (I used jython)
      from com.parasoft.api import * def combineValues (context): fromDataBank = float(context.getValue("Generated Data Source", "1. id")) fromDataSource = float(context.getValue("myData", "value2")) Application.showMessage ("Value from DataBank =" + str(fromDataBank)) Application.showMessage ("Value from DataSource =" + str(fromDataSource)) combined = (fromDataBank * fromDataSource) Application.showMessage ("Multiplied result =" + str(combined)) return str(combined)
  • OmarROmarR Posts: 176 admin

    Thank you for clarifying! Multiplication! If you wish to do some type of calculation on the fly, you will most likely require a script as suggested above (thanks for the lovely script Chris ;) )

    To add to Chris's solution:
    The "context" parameter contains most of the metadata from test runs like
    environment variables, Suite variables, databank variables, etc. A user can access the Databank values using a special Data Source name: "Generated Data Source". For example:
    value = context.getValue("Generated Data Source", "columnName")
    The "columnName" here would be the column name in the XML Data Bank.

    Similarly, to access values from a table or an excel Datasource, a user would simply use the name given to the datasource. For example:
    value = context.getValue("myTable-ds", "columnName")
    The "columnName" here would be the column name in the Table-datasource.

  • rampramp Posts: 4
    edited December 2016

    Hi Chris & Omar

     Thanks for your help so far. Would you be able to share a javascript version of the jython script  ? Or its not possible using js? I can probably do java though. Sorry to ask - there is very little documentation (apart from api listing) on scripting examples. Else I would have figured it without bothering you.

    (Btw whatever I do, the above lines are appearing in a text area, dont know how to turn it off - sorry about that).

    Also I had 2 issues while saving the xml data bank value. I was configuring the XML Data Bank tool manually using the 'Add Output' on my responder to extract a value from the request payload to use in the response payload -

    1. It was never saving it to the internal data source as promised in the help doc. When I changed it to store the value in variable, it did work.

    From doc :

    Custom column name: Tells Virtualize the name of the data source column in which to store the value. Values are stored in an internal data source unless you specify otherwise (e.g., if you select Writable data source column or Variable). This is the name you will use to reference the value in other places.

    1. I am not able to open the XML data bank tool again after closing it. It is not visible within the project or the responder suite. Am I missing something here and being plain stupid :) ?

    Thanks again for your help.

  • OmarROmarR Posts: 176 admin

    Hey ramp,

    Since we are extracting data from the request and reusing it in our Responder, we will need to enable the "Allow incoming request tools to modify the message before applying data source or multiple response correlations" option.

    Would you kindly enable the option below and re-run your scenario?

    This option is also important when the XML must be altered to make it suitable for correlation—or if the message is not XML at all and requires some transformation before the virtual asset sends the client a suitable response for the request.

    Also, regarding the disappearing databank, I am not sure why this occurred. It could have been a hiccup from eclipse not saving properly? I have yet to experience this myself. As a precaution, lets save our work after each configuration made and ensure not to have too many tabs are open at a single time.

  • rampramp Posts: 4

    Thanks Omar. That worked,

    Also the disappearing data bank was my stupidity as I had suspected. I could see when the responder node was expanded. Slightly unintuitive for a newbie, but my fault nevertheless.

    Thanks for your help.

Sign In or Register to comment.