Precisely Enterworks

 View Only
  • 1.  VTl Multiple Attributes, one output field

    Posted 08-06-2020 09:50
    I have a syndication template I am working on where I want multiple attributes to display in one column if they are true. I am not sure of the logic that would avoid each new attribute creating its own line which on the CVS export causes a new data line instead of continuing on the same row. I know the #end is what is causing the issue, I am just not sure of how to write multiple if statements where each value can be true.

    Doing my best to get better at VTL.  
    Thanks-Natalie 

    VTL
    #if(${P_Item.Gluten Free.code}=='Y')|GF|
    #end
    #if(${P_Item.Vegan.code}=='Yes')|V|
    #end
    #if(${P_Item.Kosher.code}=='Yes')|K|
    #end
    #if(${P_Item.Labeled Certified Organic.code}=='Yes')|Org|
    #end
    #if(${P_Item.Certified GMO Free.description}=='Yes')|GMOFree|
    #end

    Output in VTL Preview
    |GF|
    |V|
    |K|
    |Org|



    CVS incorrect output
    47301,,,Wisconsin,"|GF|
    |GMOFree|",,Cooler,



    ------------------------------
    Natalie Scott | Data Governance & Business Process Manager
    Gourmet Foods International | 404-210-4367
    ------------------------------


  • 2.  RE: VTl Multiple Attributes, one output field

    Posted 08-07-2020 13:04
    Hi Natalie.

    Will this work for you? I believe that I got all 32 combinations (The #else parameter is blank which would result when all variable = N). Just replace my Y's and N's of the #set commands with your fields in the header of the code. I've made them bold:

    #set($a="Y")
    #set($b="N")
    #set($c="Y")
    #set($d="Y")
    #set($e="N")
    #if ($a=='Y' && $b=='Y' && $c=='Y' && $d=='Y' && $e=='Y')|GF||V||K||Org||GMOFree|
    #elseif ($a=='Y' && $b=='N' && $c=='Y' && $d=='N' && $e=='Y')|GF||K||GMOFree|
    #elseif ($a=='Y' && $b=='N' && $c=='Y' && $d=='Y' && $e=='Y')|GF||K||Org||GMOFree|
    #elseif ($a=='Y' && $b=='Y' && $c=='N' && $d=='Y' && $e=='Y')|GF||V||Org||GMOFree|
    #elseif ($a=='Y' && $b=='Y' && $c=='Y' && $d=='N' && $e=='Y')|GF||V||K||GMOFree|
    #elseif ($a=='Y' && $b=='Y' && $c=='Y' && $d=='Y' && $e=='N')|GF||V||K||Org|
    #elseif ($a=='Y' && $b=='Y' && $c=='Y' && $d=='N' && $e=='N')|GF||V||K|
    #elseif ($a=='Y' && $b=='Y' && $c=='N' && $d=='Y' && $e=='N')|GF||V||Org|
    #elseif ($a=='Y' && $b=='Y' && $c=='N' && $d=='N' && $e=='Y')|GF||V||GMOFree|
    #elseif ($a=='Y' && $b=='Y' && $c=='N' && $d=='N' && $e=='N')|GF||V|
    #elseif ($a=='Y' && $b=='N' && $c=='Y' && $d=='Y' && $e=='N')|GF||K||Org|
    #elseif ($a=='Y' && $b=='N' && $c=='Y' && $d=='N' && $e=='N')|GF||K|
    #elseif ($a=='Y' && $b=='N' && $c=='N' && $d=='Y' && $e=='Y')|GF||Org||GMOFree|
    #elseif ($a=='Y' && $b=='N' && $c=='N' && $d=='Y' && $e=='N')|GF||Org|
    #elseif ($a=='Y' && $b=='N' && $c=='N' && $d=='N' && $e=='Y')|GF||GMOFree|
    #elseif ($a=='Y' && $b=='N' && $c=='N' && $d=='N' && $e=='N')|GF|
    #elseif ($a=='N' && $b=='Y' && $c=='Y' && $d=='Y' && $e=='Y')|V||K||Org||GMOFree|
    #elseif ($a=='N' && $b=='Y' && $c=='Y' && $d=='N' && $e=='Y')|V||K||GMOFree|
    #elseif ($a=='N' && $b=='Y' && $c=='Y' && $d=='Y' && $e=='N')|V||K||Org|
    #elseif ($a=='N' && $b=='Y' && $c=='Y' && $d=='N' && $e=='N')|V||K|
    #elseif ($a=='N' && $b=='Y' && $c=='N' && $d=='Y' && $e=='Y')|V||Org||GMOFree|
    #elseif ($a=='N' && $b=='Y' && $c=='N' && $d=='Y' && $e=='N')|V||Org|
    #elseif ($a=='N' && $b=='Y' && $c=='N' && $d=='N' && $e=='Y')|V||GMOFree|
    #elseif ($a=='N' && $b=='Y' && $c=='N' && $d=='N' && $e=='N')|V|
    #elseif ($a=='N' && $b=='N' && $c=='Y' && $d=='Y' && $e=='Y')|K||Org||GMOFree|
    #elseif ($a=='N' && $b=='N' && $c=='Y' && $d=='N' && $e=='Y')|K||GMOFree|
    #elseif ($a=='N' && $b=='N' && $c=='Y' && $d=='Y' && $e=='N')|K||Org|
    #elseif ($a=='N' && $b=='N' && $c=='Y' && $d=='N' && $e=='N')|K|
    #elseif ($a=='N' && $b=='N' && $c=='N' && $d=='Y' && $e=='Y')|Org||GMOFree|
    #elseif ($a=='N' && $b=='N' && $c=='N' && $d=='Y' && $e=='N')|Org|
    #elseif ($a=='N' && $b=='N' && $c=='N' && $d=='N' && $e=='Y')|GMOFree|
    #else
    #end​​​

    ------------------------------
    Jonathan Varo | PIM Lead
    Fender Musical Instruments | 480-845-5823
    ------------------------------



  • 3.  RE: VTl Multiple Attributes, one output field

    Employee
    Posted 12-07-2020 00:07
    Natalie,

    The issue you are having is that the newline after the value is being included in the output.  You should be able to avoid this by ending each line with a comment.  For example, the statement:

    #if(${P_Item.Gluten Free.code}=='Y')|GF|

    would become:

    #if(${P_Item.Gluten Free.code}=='Y')|GF|##

    Another option is to define a local variable that contains the output value you are building.  For each matching statement, you'd add the code to the value you are building.  If the vertical pipe character is intended to be a delimiter to separate the values, you may want to expand the logic by checking whether the value being built is empty or not.  If it's not empty, you add a pipe character then add the code.  This would result in no pipe character if only one code was set to Y and a single pipe character between codes when more than one was set.

    -Brian

    ------------------------------
    Brian Zupke | Senior Technical Support Engineer
    Winshuttle North America | 9099009179
    ------------------------------