Skip to main content

Handlebars to remove new line and return text in between characters

Comments

2 comments

  • Tyler Lamparter Senior Solutions Consultant
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Shadner Joseph will this work for you?

    {{split (replace (jsonEncode note) "\n" ",") "," 0}}
    {{split (split (replace (jsonEncode note) "\n" ",") "," 0) ": " 0}}
    {{split (split (replace (jsonEncode note) "\n" ",") "," 0) ": " 1}}

    {{split (replace (jsonEncode note) "\n" ",") "," 1}}
    {{split (split (replace (jsonEncode note) "\n" ",") "," 1) ": " 0}}
    {{split (split (replace (jsonEncode note) "\n" ",") "," 1) ": " 1}}

    {{split (replace (jsonEncode note) "\n" ",") "," 2}}
    {{split (split (replace (jsonEncode note) "\n" ",") "," 2) ": " 0}}
    {{split (split (replace (jsonEncode note) "\n" ",") "," 2) ": " 1}}

     

    Additionally, if the fields and value pairs aren't always in the same position, you may need a script to convert the string to JSON. Here is a sample transform below:

    /*
    * transformFunction stub:
    *
    * The name of the function can be changed to anything you like.
    *
    * The function will be passed one 'options' argument that has the following fields:
    *   'record' - object {} or array [] depending on the data source.
    *   'settings' - all custom settings in scope for the transform currently running.
    * The function needs to return the transformed record.
    * Throwing an exception will return an error for the record.
    */
    function transform (options) {
      
      options.record.noteJSON = {};
      if (options.record.note.split('\n').length > 0) {
        for (let [index, n] of options.record.note.split('\n').entries()) {
          if (n.split(': ').length > 0) {
            options.record.noteJSON[n.split(': ')[0]] = n.split(': ')[1];
          }
        }
      }
      
      return options.record;
    }

    1
  • Shadner Joseph

    Thank You!

    The solution below was exactly what I needed! 

    {{split (split (replace (jsonEncode note) "\n" ",") "," 0) ": " 1}}
    0

Please sign in to leave a comment.