- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 08:20 AM
Building the encoded templateFields string for the Global Update Record in a client script (api.data.update_request_record.execute). I'm doing fine with short strings and sysIds. I need to know how I can encode multiline strings (textarea content) and dates--those are erroring. It works fine when I don't add those, but that does not get me to where I need to get. Are there function samples or documentation (or someone's video) for how to encode/prep them somewhere? Or can you tell me, please.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2022 11:34 AM
Processing a textarea for api.data.update (or create, I'll presume). This preserves the line breaks to the data long String field. The backslash and caret were the only special characters I could find that need escaping, YMMV--I tested everything obvious but not the extended character sets. This works well as far as getting to the database. I am annoyed about having to spend a lot of time figuring out how to make a Save work when the functionality should be built into it, but so it goes. To be able to use my text in the email text for a flow without again losing the carriage returns, there is another step. I can apparently only put one code block in a post, so that will be a following reply.
function fixTextAreaForWrite(inputText) {
let workingText = inputText;
// Backslash MUST BE FIRST
workingText = workingText.replace(/\\/g, "\\\\");
// Carriage returns
workingText = workingText.replace(/(\r\n|\r|\n)/g, "\\n");
// Cannot make caret work, just remove
workingText = workingText.replace(/\^/g, "");
return workingText;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2024 04:17 PM
Great input, thank you for that!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2022 11:38 AM
This is the code to get from the database long string to a correctly formatted string for an email in a flow. You have to use a flow variable with a script and something like this. Note: Flow designer does not support modern JavaScript at least not in Rome, which is what I have. (Note, I just tested recovering the line breaks for this.) This one there was a pointer in another forum post, unlike the previous one which I had to put together myself.
var emailBody = fd_data.trigger.current.email_body;
var regEx = /(\r\n|\r|\n)/g;
var replaceValue = emailBody.replace(regEx, "<br/>");
return replaceValue;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2022 11:39 AM
Lastly, I did not figure out dates. I could get the date I needed another way. But if you know how to send date/time values, please share.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2024 10:50 AM
I finally rebuilt this code, and what I did is a custom GraphQL to do the save, rather than the generic GlideRecord GraphQL. It was a fair bit of work (hadn't built in GraphQL before). But this (a) made the submission take the specified fields vs the encoded query, and (b) gave me power to do whatever I wanted on the server side before the save. I still did my regex on the CRLF (and left the fix in the flows that send emails--this all works really well). I removed the regex related to the ^ character--the truncation of the string with the ^ character must have been a bug that actually got fixed. I did add a regex for the double quote:
workingText = workingText.replace(/\"/g, "\"");
and I am happier with this solution.