Notification body spacing

Bradley Bush
Mega Sage

Hi, I have a multi-line text variable that is called on in a notification. When the email notification goes out, all the entries in the variable run on continuous line even if they are spaced in the variable. 

This is what the email recipient currently receives:

 

Hello Brad,

A request was submitted for you to be able to access the queue:
dfjdj dcghjehj dfhsg 

This can also be found in the network folder located at [copy/paste this network folder path into the file explorer window address bar]: fgkhfjk fhkfuk fgkdhg 

 

This is what i would like the email recipient to receive:

 

Hello Brad,

A request was submitted for you to be able to access the queue:
dfjdj

dcghjehj

dfhsg 

 

This can also be found in the network folder located at [copy/paste this network folder path into the file explorer window address bar]:

fgkhfjk

 

fhkfuk

 

fgkdhg 

 

Thank you for looking any help would be appreciated. 

1 ACCEPTED SOLUTION

Hi @Bradley Bush ,

 

Can you give this option a try and let me know how it goes.

1. Create a mail script to handle the multiline text

2. Check the below option

JohnnySnow_0-1742511290619.png

3. Use in the notification.

 

Please mark helpful or correct if it worked out fine.

 

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

14 REPLIES 14

Hi Johnny, yes the other variables are multi-line. 

 

Capture4rrgg.JPG

output email2.JPG

@Bradley Bush yes in that case you would want them to be added in a mail script. However, I'm not sure of the exact requirement, I think you can add all the multi line text in one mail script and show them as per condition if required. I'll let you figure that out as per your requirement, if you not able to figure out let us know.

 

Also can you please mark the above answer correct since it helped you resolve the issue. This will benefit future readers.

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

AshishKM
Kilo Patron
Kilo Patron

Hi @Bradley Bush

As per need, the multiline text value need to read and split based on newLine character ( "\n") and print in loop.
You can write this code in email script and add the email script to notification using ${main_script:<email_script_name>}

 

Use the below code to convert multiline value in separate lines.

// Assume 'multilineText' is the variable containing the multiline text
var multilineText = current.variables.multiline_field; // Replace 'multiline_field' with your actual field name

// Split the multiline text into an array using the newline character
var lines = multilineText.split('\n');

// Loop through the lines and print each one
for (var i = 0; i < lines.length; i++) {
    template.print(lines[i] + '<br>'); // Use '<br>' for line breaks in HTML emails
}

 

-Thanks,

AshishKM

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

hi AshishKM,
thank you for helping with the code. below is your code with the variable replaced, where i put the mail script, and the output. not sure if i'm missing something else, the output is still the same.

 

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

          // Add your code here
// Assume 'multilineText' is the variable containing the multiline text
var multilineText = current.variables.right_task_queue; // Replace 'multiline_field' with your actual field name

// Split the multiline text into an array using the newline character
var lines = multilineText.split('\n');

// Loop through the lines and print each one
for (var i = 0; i < lines.length; i++) {
    template.print(lines[i] + '<br>'); // Use '<br>' for line breaks in HTML emails
}
})(current, template, email, email_action, event);

 

notification.JPGoutput email.JPG

Bradley Bush
Mega Sage

hi, i have tried checking the "Newlines to HTML" and using the code provided, still same output. I revamped the script and still get the same output. Any other thoughts or suggestions?

 

emailscripthead.JPG

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
          /* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
          /* Optional GlideRecord */ event) {

    // Assume 'multilineText' is the variable containing the multiline text
    var multilineText = current.variables.right_task_queue; // Replace 'right_task_queue' with your actual field name

    // Check if multilineText is defined and not null to avoid errors
    if (multilineText) {
        // Replace any \r\n combinations with \n to handle Windows-style line endings
        multilineText = multilineText.replace(/\r\n/g, '\n');

        // Split the multiline text into an array using the newline character
        var lines = multilineText.split('\n');

        // Loop through the lines and print each one
        for (var i = 0; i < lines.length; i++) {
            // Trim leading/trailing whitespace and avoid printing empty lines
            var trimmedLine = lines[i].trim();
            if (trimmedLine) {
                template.print(trimmedLine + '<br>'); // Use '<br>' for line breaks in HTML emails
            }
        }
    } else {
        // Optional: Handle the case when multilineText is empty or undefined
        template.print('No data available.<br>');
    }
})(current, template, email, email_action, event);