Function to print the report displayed on the NetSuite Dashboard using Portlet script

Attached the current view of the report displayed in the NetSuite Dashboard

function printReport() {
    // Get the selected year and month/quarter from the inputs
    const year = document.getElementById("year").value;
    const periodType = document.getElementById("periodType").value;
    let timeFrameText;


    if (periodType === "Monthly") {
        const monthSelect = document.getElementById("month");
        const month = monthSelect.options[monthSelect.selectedIndex].text;
        timeFrameText = `Sales Rep Commission Report: ${month} ${year}`;
    } else if (periodType === "Quarterly") {
        const quarterSelect = document.getElementById("quarter");
        const quarter = quarterSelect.options[quarterSelect.selectedIndex].text;
        timeFrameText = `Sales Rep Commission Report: ${quarter} ${year}`;
    }


    // Create a temporary element to hold the time frame
    const timeFrameElement = document.createElement("div");
    timeFrameElement.textContent = timeFrameText;
    timeFrameElement.style.textAlign = "center";
    timeFrameElement.style.fontSize = "1.5em";
    timeFrameElement.style.marginBottom = "20px";


    // Inject the time frame element into the report before printing
    const reportContent = document.querySelector('.commission-report').innerHTML;
    const originalContent = document.body.innerHTML;


    // Temporarily modify the body content for printing
    document.body.innerHTML = `<div>${timeFrameElement.outerHTML}${reportContent}</div>`;
    window.print();


    // Restore the original content after printing
    document.body.innerHTML = originalContent;
    window.location.reload();
}

Leave a comment

Your email address will not be published. Required fields are marked *