I need to add a check in purchase order whether the item has any minimum order qty (moq) set by the vendor. If yes make sure order qty input is more than OR equal to moq if not prompt error to user.
I created a custom record "Item Vendor Setting" to store vendor item moq with below fields
- Vendor
- Item
- Min order qty
And I created a custom transaction line field "Item Vendor id" which is list record from "item vendor setting" with filter Vendor = trans Vendor and item = trans item.
When I create a PO, after enter the Vendor and item fields, the matched ID is not auto selected in the "item vendor setting" field. Do I need any scripting to achieve this ? Can anyone advise any sample code because I can read code but cannot code from scratch :( Thanks !
I have added the client script but not sure what's wrong there is no error prompt and I can't add any line. Can anyone advise ?
/**
*@NApiVersion 2.1
*@NScriptType ClientScript
*@NModuleScope Public
*/
define(['N/currentRecord', 'N/search'],
function (currentRecord, search) {
function validateLine(context) {
var currentRecord = context.currentRecord;
var sublistName = context.sublistId;
if(sublistName === 'item') {
var recsub = currentRecord.getField({ fieldId: 'subsidiary' });
var reclineitem = currentRecord.getCurrentSublistValue({ sublistId: sublistName, fieldId: 'item'});
if (!recsub && !reclineitem) {
var subitemlinksearch = search.create({
type: "customrecord_fc_item_subsi_fields",
filters: [["custrecord_fc_isf_subsidiary", "is", recsub],'and',
["custrecord_fc_isf_item","is",reclineitem]]
});
subitemlinksearch.run().each(function (result) {
var subitemlink = result.getValue({ name: 'id' });
if (subitemlink) {
currentRecord.setCurrentSublistValue({ sublistId: sublistName, fieldId: 'custcol_fc_ir_isf_link', value: subitemlink });
};
return true;
});
};
};
}
return {
validateLine: validateLine
};
});