Handlebars to remove new line and return text in between characters
Hi Good Afternoon,
I am currently running into an issue while trying to remove the json formatting to remove the new line symbol and extract data between text. I am successfully able to extract the information using this handlebar "{{split (split note "IndustryType:" 1) "IfOTHERdescribe:" 0}}" and I am successfully able to remove the new line "\n" using this handlebar "{{replace (jsonEncode [note])"\n" ", "}}" but when I attempt to combine them such as "{{{replace (split (split note "IndustryType:" 1) "IfOTHERdescribe:" 0)(jsonEncode [note])"\n" ", "}}}" or this "{{replace (jsonEncode [note])"\n" ", "(split (split note "IndustryType:" 1) "IfOTHERdescribe:" 0)}}" it either does one or the other and not both. The text and formatting of the text being
"note": "CompanyName: Placeholder\nPosition: None\ntext-ZIED: None\nFederalTaxID: None\nResaleTaxCertificateNo: None\nResaleTaxCertificate: None\nSecondaryPhone: None\nFax: None\nLocksmithLicenseNumber: None\nIndustryType: Contractor\nIfOTHERdescribe: None\nAreYouDahuaDealer: False\nSalesContactDahuaDealer: False\nProductCategories: None\nYearsinBusiness: 0\nNumberofLocksmiths: 0\nDoyouhaveastorefront: None\nNoOfLocations: None\nAnnualSales: None\nNumberofVehicles: None\nPrimarySupplier: None\nSecondarySupplier: None\nHowdidyoufindus: None\nAgreeToTerms: True",
-
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 -
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.
Comments
2 comments