If your transaction lines should have Drop Ship/Spec Ord links in View mode, but they don’t, you can force a Drop Ship link to show up by creating a User Event script with the code in the file below (remove the .txt part of the extension first)
/**
- @NScriptType UserEventScript
- @NapiVersion 2.1
* - Add Drop Ship links
- Created by Aaron McCausland 18 Oct 2023
* - In some situations which there are Enhancement Requests for, NetSuite does not put the Drop Ship/Spec Ord links in the Create PO column of the Items sublist on a Transaction, unless the Inventory Location column is set to something.
* - To work around that, this script will attempt to create those links on those lines.
- It has to be a beforeLoad script because it needs to work in View mode, and Client SuiteScripts only work in Edit mode.
- Is it best to deploy this script in the UI execution context only, and for the View event only.
*/
define([“N/ui/serverWidget”, “N/url”], function(ui, url){
function injectClientScript(context){
const source = context.newRecord.getValue({fieldId: "source"});
log.debug(`${context.newRecord.type} with ID ${context.newRecord.id} Source (${typeof source})`, source);
const sourceWebMatch = ("" + source).match(/^Web \(/); //Only run for Webstore-created SOs
if (!(!!sourceWebMatch)){
log.debug(`${context.newRecord.type} with ID ${context.newRecord.id} is not a Webstore-created Sales Order`, "Quit");
return;
}
//Deploy this to only work in UI context for View event, not edit, not create, etc.
const customerId = context.newRecord.getValue({fieldId: "entity"});
const subsidiary = context.newRecord.getValue({fieldId: "subsidiary"});
log.debug(`${context.newRecord.type} with ID ${context.newRecord.id}`, `customerId (${typeof customer}: ${customerId}, subsidiary (${typeof subsidiary}): ${subsidiary}`);
if (!(!!customerId && !!subsidiary)){
log.debug(`${context.newRecord.type} with ID ${context.newRecord.id} is missing customer or subsidiary`, "Quit");
return;
}
const domain = url.resolveDomain({hostType: url.HostType.APPLICATION, accountId: null});
const dropShipPOUrlMain = url.resolveRecord({isEditMode: false, recordType: "purchaseorder", recordId: null});
let dropShipLinksByLineSequenceNumber = {}; //I would rather do it by lineuniquekey match, but that kept turning up blank on newly-added lines. It seems lineuniquekey is not set on new lines until the first time they are saved.
const lineCount = context.newRecord.getLineCount({sublistId: "item"});
for (let line = 0; line < lineCount; line++){
const poVendor = context.newRecord.getSublistValue({sublistId: "item", fieldId: "povendor", line: line});
if (!(!!poVendor)){
log.debug(`${context.newRecord.type} with ID ${context.newRecord.id} - No PO Vendor set on line ${line}`, "Skip");
continue;
}
const dropShipPOUrl = url.resolveRecord({isEditMode: false, recordType: "purchaseorder", recordId: null, params: {soid: context.newRecord.id, shipgroup: 1, dropship: "T", custid: customerId, nexus: 1, subsidiary: subsidiary, entity: poVendor, poentity: poVendor}});
const dropShipLinkHtml = `<a onclick="setWindowChanged(window, false);" class="dottedlink" style="white-space: pre; color: rgb(51, 102, 153); border-bottom-style: none; border-bottom-color: rgb(51, 102, 153);" href="https://${domain}${dropShipPOUrl}">Drop Ship</a>`;
const curCreatePOValue = context.newRecord.getSublistValue({sublistId: "item", fieldId: "createpo", line: line});
log.debug(`${context.newRecord.type} with ID ${context.newRecord.id} Line ${line} current "Create PO" value (${typeof curCreatePOValue})`, curCreatePOValue);
//if ("Drop Ship" != curCreatePOValue){
dropShipLinksByLineSequenceNumber[line] = "https://" + domain + dropShipPOUrl;
//}
//Setting the Create PO column during beforeLoad doesn't work, it just gets blanked out; We have to add it after the page loads, in a browser script running on the client.
}//end lineCount loop
//DOM-based approach:
let linkAdderField = context.form.addField({id: "custpage_dropshiplinkmaker", label: "Script for adding Drop Ship links", type: ui.FieldType.INLINEHTML, source: null, container: null});
linkAdderField.defaultValue = `
`;
}
return {
beforeLoad: injectClientScript
};
});
You will want to modify the contents of the script file to suit your situation.
This script file is tailored to a very specific scenario:
- INTERCOMPANY CROSS-SUBSIDIARY FULFILLMENT feature is enabled.
- The Sales Orders that were not getting Drop Ship links on their item lines were created by SuiteCommerce checkout placing the order.
This combination of factors, for some reason, caused the Drop Ship links not to appear, even on new items added to the Sales Order afterward. It also makes an alternative to this script work around the problem too: Automatically set the Inventory Location on each line you need a Drop Ship/Spec Ord link to appear. This approach didn’t make sense to us because the point of drop shipping is to skip over having things in your inventory in the first place (but it does work!).
In this particular situation, creating the exact same Sales Order any other way than via web store checkout allows the Drop Ship/Spec Ord links to appear.
For this reason, the script file specifically ignores Sales Orders that were not created from the Web Store, since we were only working around that specific problem. You can remove that from the code for your situation if needed.
The script also currently adds Drop Ship links to any line where the Create PO column is empty in the browser. You might want to discriminate further than that.
In creating the Drop Ship link, it assumes that both the “entity” and “poentity” URL parameters would be set to the same vendor, which it gets from the Item line’s PO Vendor column. I have no idea if this is the correct way to go about it, even for our particular niche situation, but I believe those two parameters are what would make one line’s Drop Ship link different from another’s.