I'm writing a RESTlet that will allow my team to create Cash Sales from a local app. For some reason, though, the script fails to provide any subsidiary to pick from. I must select a subsidiary because I must select a location.
I've tried using getSelectOptions, since that field is the select type, and it returns no options. I have also tried changing the record to a sales order, but it made no difference.
The script is running, for debug purposes, as my user with admin rights, so permissions shouldn't be an issue.
/**
* @NApiVersion 2.1
* @NScriptType Restlet
*/
define(['N/log', 'N/record', 'N/search'],
/**
* @param {log} log
* @param {record} record
* @param {search} search
*/
(log, record, search) => {
/**
* @typedef RequestedOrderItem
* @prop {string} upc The UPC of the item to add
* @prop {number} quantity The quantity of the item to add
*/
/**
* @typedef RequestedOrder
* @prop {number} customer The internal ID of the customer to assign the order to
* @prop {RequestedOrderItem[]} items The items to add to the order
*/
const posLog = (message, title="") => {
log.debug({
title: "POS Receiver"+(title ? ` - ${title}` : ""),
details: message
});
}
/**
* Defines the function that is executed when a POST request is sent to a RESTlet.
* @param {RequestedOrder} requestBody - The HTTP request body; request body is passed as a string when request
* Content-Type is 'text/plain' or parsed into an Object when request Content-Type is 'application/json' (in which case
* the body must be a valid JSON)
* @returns {string | Object} HTTP response body; returns a string when request Content-Type is 'text/plain'; returns an
* Object when request Content-Type is 'application/json' or 'application/xml'
* @since 2015.2
*/
const post = (requestBody) => {
const order = requestBody;
const cashSale = new record.create({
type: record.Type.SALES_ORDER,
isDynamic: true
});
const locationField = cashSale.getField({
fieldId: "location"
});
const locationOptions = locationField.getSelectOptions();
const subsidiaryField = cashSale.getField({
fieldId: "subsidiary"
});
const subsidiaryOptions = subsidiaryField.getSelectOptions();
posLog(subsidiaryOptions, "Subsidiary options");
// posLog(locationOptions, "Location options"); // Won't show any options until subsidiary is selected
// This fails with INVALID_FLD_VALUE since there are no valid values
// cashSale.setValue({
// fieldId: "subsidiary",
// value: 2 // This IS the subsidiary ID
// });
// cashSale.setValue({
// fieldId: "location",
// value: 4 // This IS the location ID
// });
// cashSale.save();
return {success: true};
}
return { post };
});
I use the exact same subsidiary and location setting with a RESTlet that creates Assembly Builds and it works there.
Is there some obvious reason why I'm unable to select a subsidiary, and thus a location, for a cash sale?