Custom Print Button in Inventory Transfer

Hello

I need some guidance in setting up a custom print button in the inventory transfer form, I see the form has the printing field but the form itself doesn’t have the print button.

Any help would be appreciated.

Rookie Asked on May 12, 2022 in SuiteScript.
Add Comment
11 Answer(s)

You should be able to add a button using a User Event script.

You’ll also need an accompanying client script to handle the button action.

Please let me know if you need further details.

Advanced Answered on May 17, 2022.
Add Comment

Yes, I was able to create the button with a user event. How can I make the CS so the button can call it?

Thanks for answering.

Best

Rookie Answered on May 17, 2022.
Add Comment

Hi,

First, you need to reference a client script using:

form.clientScriptModulePath = './client_script.js';

When you add the button in the User Event script, there is a functionName argument.

The client script needs to implement that function.

Thanks,

Chris

Advanced Answered on May 17, 2022.
Add Comment

I see but what module do I need to use to print? that’s the part I get lost. Now I know how to call the UE but how to print?

Thank you for your time.

Rookie Answered on May 17, 2022.
Add Comment

Hi,

To do the actual printing you’ll need to use that client script function to call a Suitelet and in the Suitelet, do something like this:

let renderer = render.create();
renderer.setTemplateById({ id:123 });
...
scriptContext.response.addHeader({
    name: 'Content-Type:',
    value: 'application/pdf'
});
scriptContext.response.addHeader({
    name: 'Content-Disposition',
    value: 'inline; filename=”Test.pdf"'
});
scriptContext.response.writeFile(renderer.renderAsPdf());
Advanced Answered on May 17, 2022.
Add Comment

Thank you, I’ll try.

Rookie Answered on May 17, 2022.
Add Comment

Hello Again, I tried to build the script but I’ve failed, would you please help me find the issue? below  the UE, SC, suitelet.

**User Event**

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define([],
    function() {
        function beforeLoad(scriptContext) {
            try{
                if ((scriptContext.type).toLowerCase()  != ‘create’) {
                    var objTransactionForm = scriptContext.form
                    objTransactionForm.clientScriptFieldId = 9999; // ID clientscript field
                    objTransactionForm.addButton({
                        id          : ‘custpage_printinventorytransfer’,
                        label       : ‘Print’,
                        functionName: ‘printInventoryTransfer()’
                    });
                }
            }catch(e){
                log.error({
                    tittle: e.name,
                    details: e.message
                })};
        }
        return {
            beforeLoad: beforeLoad
        };
    });
**Client Script**
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define([
    ‘N/currentRecord’,
],
function(currentRecord) {
    function pageInit() {
    }
    function printInventoryTransfer() {
        var record = currentRecord.get();
        var recId = record.id;
        var recType = record.type
        var suiteletURL = url.resolveScript({
         scriptId:’customscriptcase3783737_suitelet’,//Please make sure to replace this with the script ID of your Suitelet
         deploymentId: ‘customdeploycase3783737_suitelet_dep’,//Please make sure to replace this with the deployment ID of your Suitelet
         params: {
     ‘recId’:recId,
    ‘recType’:recType
         }
         });
      document.location=suiteletURL;
         };
    return {
        pageInit : pageInit,
        printInventoryTransfer : printInventoryTransfer,
        };
    });
**Suitelet**
/**
 * @NApiVersion 2.1
 * @NScriptType Suitelet
 */
define([‘N/render’],
function(render) {
function returnPDF(scriptContext) {
    let renderer = render.create();
    renderer.setTemplateById({ id:52 });
    scriptContext.response.addHeader({
        name: ‘Content-Type:’,
        value: ‘application/pdf’
    });
    scriptContext.response.addHeader({
        name: ‘Content-Disposition’,
        value: ‘inline; filename=”Test.pdf”‘
    });
    scriptContext.response.writeFile(renderer.renderAsPdf());
}
  return {
    onRequest: returnPDF
  };
});
Thank you

 

 

Rookie Answered on May 23, 2022.
Add Comment

Hi,

It’s looking like you have all the main parts. One thing that springs out is that I’d expect to see:

functionName: ‘printInventoryTransfer’ (without the braces)

How far are you getting and is there any error?

Thanks,

Chris

Advanced Answered on May 23, 2022.
Add Comment

It does nothing when I click on the button

Thanks for answering

Rookie Answered on May 23, 2022.
Add Comment

If you open the Developer Tools Console in your browser, do you see any error message?

Advanced Answered on May 23, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Become a Sponsor   Become a Sponsor