is it possible for the submit button of a portlet ...
# suitescript
s
is it possible for the submit button of a portlet to fire a client script
b
the answer is yes, but honestly its probably better to add your own button
you can use javascript as the scheme of your submit button's url to run javascript
i personally would just add a button element to your portlet's form and add your code there
make sure to use the type attribute if you create your own button, its literally inside a form element and by default behaves like a submit button
s
@battk just to give some context the user is submitting a shipment id and the client script will print the shiping label
how can i get the submit button of my portlet for call that function
Copy code
portlet.setSubmitButton({
      url: "output",
      label: "Submit",
      target: "_hidden",
    });               function _print_api() {
    console.log("testing");
    // print_shipping_label(document.forms["main_form"].orderid.value, id);
  }
b
i personally expect your approach to change later on
print_shipping_label doesnt exist in a portlet
that said, use Portlet.addField to add an linline html field so you can add your own button
s
Copy code
var newfld = portlet.addField({
      id: "custpage_ng2",
      type: serverWidget.FieldType.INLINEHTML,
      label: "button",
      source: '<button type="button"> Add to favorites</button>',
    });
like this ?
b
thats not how the source works.
use Field.defaultValue to set the value of the html
s
how can a custom button call the function inside a client script as "print_shipping_label" is only available in client script
b
The html is evaluated by a browser
It is clientside
That said, I told you in the beginning, I expect that you will need to change your approach
print_shipping_label is an internal netsuite function that is only available on certain pages
s
so do you have any better ideas to repirnt the shipping label
b
Im not sure if you can print shipping labels using N/render
If you can, you would want to make a suitelet that creates you shipping labels and use that servlet with your button
s
I'm not trying to create shipping ;label but to reprint those attached to the IF
b
Printing in suitescript consists of writing a file to the output
If you want to use N/render, then you will be creating a new file object
You can load an existing file if it already exists