using plain XML Message responder

jimboyjimboy Posts: 33

This is odd, may be just my configuration. I have literally copied the response and past to input mode literal Then I change it to the following input mode below.

When the input mode is form input. The data source works fine as well as the generating script works based on the data source. However, the issue I encounter here is that I could not exclude an empty string by right-clicking the element (which works fine on form XML).

When the input mode is form XML. The data source works fine as it was able to read the data source. I have tested the data source where it's empty and it's also removing the empty elements. However, What trouble me here is that the script is either not picking up the data source or not generating the values.

The script on both from Input and form XML are the same. I just don't know the script works on form input but not on form xml and why on form input I cannot right click to exclude an empty string on form input.

What's is the best approach

Comments

  • williammccuskerwilliammccusker Posts: 528 ✭✭✭

    Hi,

    Could you describe more what you mean when you say "the script"? Are you scripting an element? Or is there an extension tool chained to the responder? It would be helpful to understand more about where the script is to be able to understand what might be happening. Depending on where scripts are attached they have different input arguments so knowing the exact location of your script would be very helpful, thanks!

  • jimboyjimboy Posts: 33
    edited June 30

    the script is attached to the element on both form xml and form input. It works well on input mode Form Input but not on Form XML. Please see attached screenshot for transactionPostingDate.

  • williammccuskerwilliammccusker Posts: 528 ✭✭✭

    Hi,

    Is the script directly accessing the data source to read the values? Has a Data Source Correlation been set up for this responder? Without a data source correlation, the behavior when trying to read from the data source is undefined. Some places may use the first row other places will not find the data at all.

    Search for "Data Source Correlation Tab"
    https://docs.parasoft.com/display/VIRT9106/Message+Responder+Overview#MessageResponderOverview-ResponderCorrelationTab

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭

    Please also see my response to your earlier thread.
    From virtualize response:

    The responder can pull values from data source columns if your responder has data source correlation configured.

    If you are executing a script somewhere that needs to read values from a data source then make sure you also selected the "Use data source" checkbox above the Language selector.

  • jimboyjimboy Posts: 33

    In both cases, the data source correlation is enabled where input mode form input work perfectly with the scripting element. but, when the input mode is form XML it does not work. I tried to log the output using the method log.info to the console. But, it does not work on virtualize. Is there a way to log the output of the script somewhere.

  • williammccuskerwilliammccusker Posts: 528 ✭✭✭

    Hi,

    To print messages to the console there is a class called Application with a method called showMessage that scripts can you. There are examples of on this documentation page along with other information about scripting.

    https://docs.parasoft.com/display/SOAVIRT9103CTP310/Extensibility+and+Scripting+Basics

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭

    but, when the input mode is form XML it does not work

    For the scripted element, did you confirm whether the "Use data source" checkbox is selected?

  • jimboyjimboy Posts: 33

    On the script, the user data source is selected. On the Parasoft event details. It was able to see it selected row 1. Any fixed value in the data source is being passed to the responder. What really bugs me is that anything that is scripted for each element. It was not able to find the Data Source column name (even though it exists) in the data source. I have attached a script snapshot. Just want to reiterate that this works well on form input but not on form XML.

    import com.parasoft.api.*;
    import java.lang.*;
    import java.util.*;
    import java.text.DecimalFormat;

    public addDataSource(context){
    return "DataSourceName"
    }

    public setCreationTimeStamp( context){
    dateTime = context.getValue("DataSourceName","creationTimestamp")
    if (dateTime == "AUTO"){
    return new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    } else {
    return dateTime
    }
    }

  • williammccuskerwilliammccusker Posts: 528 ✭✭✭

    Hi,

    I cannot reproduce your issue. I tried a script and it works from both Form Input and Form XML. Perhaps there is something else in the asset configuration that could be causing this? Would you be able to share an example pva file that reproduces the issue? Also what version of the product are you using?

  • jimboyjimboy Posts: 33

    I wish I can send you the PVA file. Unfortunately, it's not allowed. I am using soatest and virtualize version 2020.2

  • williammccuskerwilliammccusker Posts: 528 ✭✭✭

    Hi,

    I tested using the exact script in 2020.2 and it works for me. I think you may need to contact technical support. I suspect there is something in your setup that is different than what I am creating but without being able to see even a sample pva it's really hard to guess what might be different. It doesn't have to be the actual pva, which I understand might contain sensitive information, but a basic reproducing use case would be helpful. In case it helps here is the pva file I created.

  • jimboyjimboy Posts: 33

    I have created a sample using form Input and form XML. On the sample, there is two input mode. You would notice that it on form Input. If it was able to pick up the script and send to a response. But, form XML it was not able to execute the script.

  • jimboyjimboy Posts: 33

    I was trying this out to determine where it's actually failing. So I intentionally change the script. Both samples scripts below have datasource enabled. I notice that when I name DataSourceName to the actual file in the excel sheet. It works fine.

    actual script (not working)
    import com.parasoft.api.*;
    import java.lang.*;
    import java.util.*;
    import java.text.DecimalFormat;

    public addDataSource( context ){
    return "DataSourceName"
    }

    public setCreationTimestamp(context){
    dateTime = context.getValue( "DataSourceName", "creationTimestamp" )
    if (dateTime == "AUTO" ){
    return new Date().format( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
    } else {
    return dateTime
    }
    }

    revised script to point directly to the dataSourceName. Here you would see test is the name of the datasource

    import com.parasoft.api.*;
    import java.lang.*;
    import java.util.*;
    import java.text.DecimalFormat;

    public setCreationTimestamp(context){
    dateTime = context.getValue( "test", "creationTimestamp" )
    if (dateTime == "AUTO" ){
    return new Date().format( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" );
    } else {
    return dateTime
    }
    }

  • williammccuskerwilliammccusker Posts: 528 ✭✭✭

    Hi,

    I see, in your case you are using an excel data source? So the script works when you use the name of the excel spreadsheet? I had been testing with the built-in table data so that is probably why I was seeing different behavior.

  • benken_parasoftbenken_parasoft Posts: 1,009 ✭✭✭
    edited July 6

    I notice that when I name DataSourceName to the actual file in the excel sheet.

    You must use the actual name of the data source in your pva. Data source values are accessed by calling context.getValue("Data Source Name", "Column Name") where you substitute "Data Source Name" and "Column Name" with the real data source name and column name. Similarly, your addDataSource method must return the actual data source name.

  • jimboyjimboy Posts: 33

    got it

Sign In or Register to comment.