Precisely Enterworks

 View Only
  • 1.  VTL Help Needed | Replacing A Double Quote

    Posted 06-26-2020 17:11
    Hi Everyone! Lorenzo here from McNichols Co. We're hot and heavy into our implementation and I've been working with my team to create Calculation Rules using VTL. We have one rule that is really stumping us, but it seems like it should be so simple.

    We have two Attributes, one is called "Expanded Style", and the second is "Expanded Style Alternate". All I want to do is replace part of the value.

    Example:
    I want to make the above image, look like the below image:
    Here is what our VTL looks like:
    #set($es='')
    #set($es=${Expanded Style})
    #set($es=$es.replace('" No. ',' #'))
    $es​

    This actually does not work. So we tried breaking it down into steps:
    #set($es="")
    #set($es=${Expanded Style})
    #set($es=$es.replace("No. ","#"))
    $es​

    The above works, but doesn't give us out desired result, we end up with this:

    So we took it a step further with multiple variations of this:
    #set($es="")
    #set($es=${Expanded Style})
    #set($es=$es.replace("No. ","#"))
    #set($es=$es.replace("""",""))
    $es​

    Nothing we have tried works. We simply cannot figure out how to replace a double quote with a blank.

    Has anyone figured out how to replace a double quote in VTL?

    ------------------------------
    Lorenzo Francisco | Data Analyst
    McNichols Company | 813-625-9369
    ------------------------------


  • 2.  RE: VTL Help Needed | Replacing A Double Quote

    Posted 06-26-2020 18:03
      |   view attached
    Lorenzo,

    See if this works for you.

    #set($es="${Expanded Style}")
    #set($es=$es.replace('" No. ',' #'))
    $es​

    I think it was in your #set commands that the problem started.

    The single quotes that you have around '" No. ' is the correct way to go about replacing double quotes. I confirmed that it worked by placing your original value in one of my unused fields in my QA instance and ran a syndication template with your VTL (with the little edit I did in the beginning). The attached spreadsheet was my output.

    Best regards,


    ------------------------------
    Jon Varo | PIM Analyst
    Fender Musical Instruments | \+1 480 596 9690
    ------------------------------



  • 3.  RE: VTL Help Needed | Replacing A Double Quote

    Posted 07-09-2020 08:17
    Hi John,

    Thank you for your suggestion. Sorry for taking so long to reply, I'm pretty deep in getting our PIM setup. It appears that the VTL used in a syndication template seem to function slightly different than the VTL used to calculate a new attribute in the UI itself. We were able to also see the correct result in a template, but not the UI using the same VTL. We do seem to have a work around in place that's working, but it's not a final fix. Once we have it fixed, I'll report back.

    ------------------------------
    Lorenzo Francisco | Data Analyst
    McNichols Company | 813-625-9369
    ------------------------------



  • 4.  RE: VTL Help Needed | Replacing A Double Quote

    Posted 07-09-2020 09:53
    Hi Lorenzo,

    Glad to hear that you found a workaround. I'm a little concerned about VTL working differently in two separate areas of PIM though. It might warrant a  report to your support rep.

    Just curious though... where are you performing your calculations? Are you using rules in the Profile of your repository? If you can give me a little more info, I can work the problem on my end and see if I can get it to work. It will also allow me to determine if my system is able to calculate it correctly outside of the Syndication Templates.

    Best regards,

    ------------------------------
    Jon Varo | PIM Team Lead
    Fender Musical Instruments | \+1 480 596 9690
    ------------------------------



  • 5.  RE: VTL Help Needed | Replacing A Double Quote

    Posted 05-24-2021 14:49
    Hi Lorenzo, 

    I have a similar use case,  want to remove double quotes in the string E.g. Over&" to 8 " -> Over-7-to-8

    #set( $nv = $nv.replaceAll( '[\"]+', '' ) ) --> this doesn't work


    #set( $n = $nv.replaceAll("&quot","")) -> this does work for the first time but when I click into the VTL rule it's reset to
    #set( $n = $nv.replaceAll(""","")), if saved this will fail again.


    Were you able to figure out a way to replace the double quotes?

    Thanks, 

    Deepika




  • 6.  RE: VTL Help Needed | Replacing A Double Quote

    Posted 05-25-2021 03:59
    Hi Deepika,

    Please try below options:

    Option 1
    #set($q = '"')##
    #set ($nv="Test double quotes")##
    #set ($a = $nv.replace("$q",' '))
    $a


    Option 2
    #set($v=${Column Name})
    #set($e=$v.replace('"',''))
    $e

    Thanks
    Pavan

    ------------------------------
    Pavan Kumar | Business Analyst
    Ecolab |
    ------------------------------



  • 7.  RE: VTL Help Needed | Replacing A Double Quote

    Posted 06-03-2021 08:59
    @Deepika Jaggi

    I would use unicode (\u0x22) instead of ". I believe that the HTML is being interpreted by the browser and being changed by it.

    #set( $n = $nv.replaceAll("\u0x22", ""))

    Also, whenever I use data, I tend to single quotes to encapsulate the data. Makes it a little easier to read.

    #set( $n = $nv.replaceAll('\u0x22', ''))

    Best regards,

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