Abed Timsah
Abed Timsah

Reputation: 11

Netsuite SuiteScript : Button to open new transaction from custom record and Default fields

I am trying to create buttons on a custom record called processing batch that would allow me to create work orders and inventory transfers. The buttons would simply open a new page and does not save a new transaction, simply a redirect to the new transaction page.

On these transactions, there's a custom field called Processing batch that is a list of the custom record and I want that field to default to the id of the batch where the button was clicked.

I have a usereventscript for the buttons and a client script to open the links.

User Event:

define([],

function() {

function beforeLoad(context) {
    context.form.addButton({
        id: "custpage_workorderbutton",
        label: "Create New Work Order",
        functionName: "newWorkOrder"
    });
    context.form.addButton({
        id: "custpage_inventoryTransferButton",
        label: "Create New Inventory Transfer",
        functionName: "newInventoryTransfer"
    });
    context.form.clientScriptModulePath = "SuiteScripts/CreateNewWO.js";
}


return {
    beforeLoad: beforeLoad,
};

});

Client Script: (dialog was defined for testing purposes but won't be needed)

define(['N/ui/dialog'],

function(dialog) { var exports = {};

function pageInit(context) {

}
function newWorkOrder(){
    window.open("https://6236296.app.netsuite.com/app/accounting/transactions/workord.nl?whence=");
}

function newInventoryTransfer(){
    window.open("https://6236296.app.netsuite.com/app/accounting/transactions/invtrnfr.nl?whence=");
}

exports.newInventoryTransfer = newInventoryTransfer;
exports.newWorkOrder = newWorkOrder;
exports.pageInit = pageInit;

return exports;

});

Anyone has an insight on how I would be able to achieve my goal?

Thank you in advance.

Upvotes: 0

Views: 3457

Answers (2)

Jala
Jala

Reputation: 919

You can also try adding 'record.' as prefix to your custom field when you pass it as a parameter. E.g. 'invtrnfr.nl?record.batchId=1'

This will also work for standard fields.

Reference: https://blog.prolecto.com/2018/05/20/drive-values-to-netsuite-forms-and-other-url-tricks/

Extra note: You may also want to check url.resolveDomain and url.resolveTaskLink to build the URL. :)

Upvotes: 1

Arie White
Arie White

Reputation: 58

Here are two ways for you to do this.

  1. Pass a parameter in the open URL by adding

'&yourparamname='+ idvalue to the URL that is opening the transaction window

If you pass a parameter into the URL, you can then use an onInit script deployed to the transaction page to get the parameter out of the URL and do as you please.

  1. You can use window.opener.nlapiGetFieldValue(yourfield) to get values from the page that the popup came from, and then use that value to set the field on the transaction page

Those are just two ways. I hope this helps.

Upvotes: 0

Related Questions