Phase 4 ยท Reference Material

JavaScript Library

Phase 4 extends the JavaScript Library with practical Lasernet scripting patterns, string handling, JobInfo usage, Base64 handling, and HTML output helpers.

ArraysBase64ConditionsCurrentTextHTML OutputJobInfoNull HandlingStrings
Redacted samples: Sensitive names, URLs, IDs, customer values, infrastructure details, and project-specific values have been replaced with generic placeholders.

Read a JobInfo

Reads a JobInfo value into a variable.

var value = job.getJobInfo("<JobInfoName>");

When to use

Use when a module needs metadata created earlier in the workflow.

Notes

Always handle missing or empty values.

Set a JobInfo

Writes a calculated value back to JobInfo.

job.setJobInfo("<JobInfoName>", value);

When to use

Use to pass values to later modules such as MailOut, PDF, output, or archive steps.

Notes

Do not overwrite an existing JobInfo unless that is intentional.

Read JobInfo Count

Reads how many values exist for a repeated JobInfo.

var count = job.getJobInfoCount("<JobInfoName>");

When to use

Use when processing arrays such as multiple printers, copies, recipients, or attachments.

Notes

Count may be zero; guard your loop.

Loop Repeated JobInfo Values

Loops through indexed JobInfo values.

var count = job.getJobInfoCount("<JobInfoName>");
for (var i = 0; i < count; i++) {
    var value = job.getJobInfo("<JobInfoName>", i);
    // process value
}

When to use

Use when the same JobInfo name contains multiple values.

Notes

Confirm the exact Lasernet API overload available in your version.

Trim and Compare Lowercase

Normalizes text before comparison.

CurrentText.trim().toLowerCase() == "no"

When to use

Use for case-insensitive yes/no style checks.

Notes

Guard against null if CurrentText may be missing.

Ternary Yes/No Output

Short conditional expression for object text output.

(CurrentText.trim().toLowerCase() == "no") ? "X" : "";

When to use

Use for short field-level output conditions.

Notes

Use normal if/else when the logic becomes hard to read.

Non-empty and Not No

Checks text is not empty before applying comparison logic.

(CurrentText != "" && CurrentText.trim().toLowerCase() == "no") ? "" : "X";

When to use

Use when blank values should not be treated the same as no.

Notes

Confirm the desired blank behavior before using.

Create Dynamic Hyperlink

Builds an HTML anchor from a JobInfo URL.

var url = job.getJobInfo("<UrlJobInfo>");

if (url && !/^https?:\/\//i.test(url))
    url = "https://" + url;

CurrentText =
    '<a href="' + url + '" target="_blank">' +
        '<span style="text-decoration:none;color:#ffffff;font-weight:bold;">' +
            'Click to Pay' +
        '</span>' +
    '</a>';

When to use

Use for clickable buttons or links in HTML output.

Notes

Some email clients may ignore target="_blank".

Simple Pay Here Link

Static HTML link sample.

<a href="https://www.example.com">Pay here</a>

When to use

Use for simple hyperlink testing before adding dynamic JobInfo logic.

Notes

Replace example.com with a redacted or approved public URL only.

Decode Base64 PDF to Binary JobInfo

Decodes a Base64 PDF string and stores it as binary JobInfo.

var b64 = job.getJobInfo("<Base64JobInfo>");
if (b64) {
    b64 = ("" + b64).replace(/\s+/g, "");
    var pdfBin = Base64.decode(b64);
    job.setJobInfoBinary("MailAttachment", pdfBin);
}

When to use

Use when XML or API data contains a Base64 PDF that must be emailed.

Notes

Always remove whitespace before decoding.

Multiple PDF Attachments Pattern

Loops through repeated Base64 values and creates multiple binary attachments.

var count = job.getJobInfoCount("<Base64JobInfo>");
for (var i = 0; i < count; i++) {
    var b64 = job.getJobInfo("<Base64JobInfo>", i);
    if (!b64) continue;
    b64 = ("" + b64).replace(/\s+/g, "");
    var pdfBin = Base64.decode(b64);
    job.setJobInfoBinary("MailAttachment", pdfBin);
}

When to use

Use when each Base64 document should remain a separate email attachment.

Notes

Confirm attachment name handling separately.

Build Safe Dynamic Filename

Combines fields and removes illegal filename characters.

var name = job.getJobInfo("<DocumentNumber>") + "_" + job.getJobInfo("<Account>");
name = name.replace(/[\\/:*?"<>|]+/g, "_");
job.setJobInfo("<OutputFileName>", name + ".pdf");

When to use

Use for output/archive/email attachment filenames.

Notes

Avoid exposing customer-specific values in documentation samples.

Basic Array Join

Joins values into a comma-separated string.

var values = ["One", "Two", "Three"];
CurrentText = values.join(", ");

When to use

Use when collecting repeated values into one display field.

Notes

Do not use if each value must remain a separate JobInfo.

Safe CurrentText Default

Converts null or undefined CurrentText to an empty string.

CurrentText = (CurrentText == null) ? "" : "" + CurrentText;

When to use

Use before trim, replace, or lowercase operations.

Notes

This intentionally converts numbers to strings.

Related Topics

Phase 5 adds related-topic guidance to reduce duplicate entries and make reusable patterns easier to find.

RedactedReviewedCanonical