Leave feedback
  • Question

    Problems formatting fields in a table in Storyteller

Enter a new topic
  • Liz Atkins Liz Atkins
    0 likes 1019 views

    Hi,

      I’m new to Storyteller and I’m having problems formatting some fields on a page.

      I’ve created a story and within that story I’m displaying customer details and their orders. The customer details part is fine, I’ve created a table for the orders and my problem is that I need to display a description for each order rather than the code which is passed to Storyteller in the XML.

      I have tried a couple of ways of dealing with this, but with no success.

      One attempt was to use an existing message (XMLIN to XMLOUT) to decode the order code, but the problem is that this message is at document level (a document being a customer block and a repeating order block). This means that when I write the order description to the variable attached to the XML, it’s only written to the XMLOUT once per document. Are there any message traversing functions which allow me to update the XML variable / element as I need? Or is there any other scripting method I can use?

      Another attempt was to use the scripting within Storyteller to do the job. This also failed. I have tried setting the order code as a variable within the XMLIN but as orders are at a lower level than the document, this variable is not displayed for use within Storyteller if I use the modification on the order code field. Do I need to use Xpath to handle this? If so, how? I understood that there is no IF statement within Xpath so I’m at a loss as to how I can use it for this task.

    Any help anyone can offer would be very much appreciated.

    Thanks,

    Liz

    Monday 23 December, 2013
  • Best Answer
    David Bares David Bares OpenText Employee Administrator StreamServe Employee
    0 likes

    Following XPath:
    /data/message/Block_PRODUCT_LEVEL_1/PRODUCT_TYPE_L1

    selects all the PRODUCT_TYPE_L1 fields in your message into a single node set. When assigned to variable, conversion to string is performed. Nodeset conversion to string is defined as value of first node or empty string. That is why you get the first value all the time.

    Since the script you are calling is executed within the repeater (I assume
    /data/message/Block_PRODUCT_LEVEL_1), you need to use relative path instead of absolute path.

    $productTypeTemp = stEvalXPath("PRODUCT_TYPE_L1");

    That would select only the current value for the field.

    Alternatively you can use "./PRODUCT_TYPE_L1", or "current()/PRODUCT_TYPE_L1" or "self::Block_PRODUCT_LEVEL_1/PRODUCT_TYPE_L1", but why would you do it?

    Just note there is a difference in Absolute and Relative XPath. Absolute returns the same from which ever context you call it. Relative is context dependent.

    Tuesday 07 January, 2014
  • David Bares David Bares OpenText Employee Administrator StreamServe Employee
    0 likes

    I understand that the order has a code that is passed to StoryTeller from the XML.

    But where is the description coming from?

    Is there some lookup table with code as a key and description as a value?

    Or is such table present in the XML? Something like what I have attached? In that case it is possible to address the description text using XPath.

    Thursday 02 January, 2014

    Attached files

  • Liz Atkins Liz Atkins
    0 likes

    Hi David,

    Thank you for the reply. At present, the description is not passed anywhere in the XML. I was hoping to hardcode the description in a script as there are only 5 different descriptions and it's highly unlikely that we'll need more.

    Alternatively, I can create a lookup table, but I don't know how or where in Storyteller to read the lookup table. Any help you can offer would be much appreciated.

    Thanks,

    Liz

    Thursday 02 January, 2014
  • David Bares David Bares OpenText Employee Administrator StreamServe Employee
    0 likes

    In case of descriptions hardcoded in script it is super simple. Create a script somewhere within the repeater and set value of $variable. Then use XPath: $variable to retrieve the value. See attached.

    But it would be more professional to separate the descriptions into lookup table. In that case I would look at Substitution table functions

    $description = Subst("../data/tables/descriptions.tbl",stEvalXPath("code"));

    Thursday 02 January, 2014

    Attached files

  • Liz Atkins Liz Atkins
    0 likes

    Hi David,

      Thank you for your help. I’ve tried both methods now (the hardcoding and the new table). I certainly agree that using a table is a more professional solution, but I was struggling to get this to work at all, I will be using the table for the final solution.

     I’ve followed your example and I now get a description displayed, but it’s always the same description, the one relating to the first order line. I would have expected that by using a before script on the cell (as in the example you sent me ) that the script would run each time the cell is used. Is this not the case? Do I need to add a counter and loop to check which order line I’m trying to decode?

     This is the script I’m using:

    clear($productType);

    clear($productTypeTemp);

    $productTypeTemp = stEvalXPath("/data/message/Block_PRODUCT_LEVEL_1/PRODUCT_TYPE_L1");

    $productType = Subst("..\Management Tables\ProductTypes.tbl",$productTypeTemp);

    log(0, "product type temp = " + $productTypeTemp);

    log(0, "product type  = " + $productType); 

    I must have missed something, but I don’t know what it is, any ideas?

    Thanks,

    Liz

    Tuesday 07 January, 2014
  • David Bares David Bares OpenText Employee Administrator StreamServe Employee
    0 likes

    Following XPath:
    /data/message/Block_PRODUCT_LEVEL_1/PRODUCT_TYPE_L1

    selects all the PRODUCT_TYPE_L1 fields in your message into a single node set. When assigned to variable, conversion to string is performed. Nodeset conversion to string is defined as value of first node or empty string. That is why you get the first value all the time.

    Since the script you are calling is executed within the repeater (I assume
    /data/message/Block_PRODUCT_LEVEL_1), you need to use relative path instead of absolute path.

    $productTypeTemp = stEvalXPath("PRODUCT_TYPE_L1");

    That would select only the current value for the field.

    Alternatively you can use "./PRODUCT_TYPE_L1", or "current()/PRODUCT_TYPE_L1" or "self::Block_PRODUCT_LEVEL_1/PRODUCT_TYPE_L1", but why would you do it?

    Just note there is a difference in Absolute and Relative XPath. Absolute returns the same from which ever context you call it. Relative is context dependent.

    Tuesday 07 January, 2014
  • Liz Atkins Liz Atkins
    0 likes

    That's sorted it!

    Thanks for all your help David, it's been very much appreciated!

    Liz

    Tuesday 07 January, 2014