Hi
I have the following client script which i would expect would trigger when the vendor name or subsidiary is changed on a vendor bill record (which is where it is deployed). Can you see what is wrong with the script? This isn't returning an error though isn't logging anything with console.log (deleted) or log.debug(current version of script)
/**
@NApiVersion 2.x@NScriptType ClientScript
*/
define(['N/search', 'N/record', 'N/log'], function(search, record, log) {function fieldChanged(context) {
var currentRecord = context.currentRecord; var fieldId = context.fieldId; // Logging the current record and the field ID log.debug('Current Record', JSON.stringify(currentRecord)); log.debug('Field ID', fieldId); // Trigger the search when the vendor or subsidiary field changes if (fieldId === 'entity' || fieldId === 'subsidiary') { var vendorName = currentRecord.getText('entity'); // Get vendor name var subsidiaryName = currentRecord.getText('subsidiary'); // Get subsidiary name log.debug('Vendor Name', vendorName); log.debug('Subsidiary Name', subsidiaryName); if (vendorName && subsidiaryName) { // Perform the search to find the vendor payment method var vendorPaymentMethod = searchVendorPaymentMethod(vendorName, subsidiaryName); if (vendorPaymentMethod) { log.debug('Vendor Payment Method', vendorPaymentMethod); alert('Vendor Payment Method: ' + vendorPaymentMethod); } else { log.debug('No payment method found', 'No matching payment method found for vendor and subsidiary.'); alert('No payment method found for the selected vendor and subsidiary.'); } } }}function searchVendorPaymentMethod(vendorName, subsidiaryName) {
var vendorPaymentMethod = null; // Create the vendor subsidiary relationship search var vendorsubsidiaryrelationshipSearchObj = search.create({ type: "vendorsubsidiaryrelationship", filters: [ ["vendor.entityid", "contains", vendorName], "AND", ["subsidiary.legalname", "contains", subsidiaryName] ], columns: [ search.createColumn({ name: "entity", label: "Vendor" }), search.createColumn({ name: "subsidiary", label: "Subsidiary" }), search.createColumn({ name: "custrecord_ven_pymt_methods", label: "Vendor Payment Method" }) ] }); // Log the search parameters log.debug('Search Parameters', { vendorName: vendorName, subsidiaryName: subsidiaryName }); // Run the search and log results vendorsubsidiaryrelationshipSearchObj.run().each(function(result) { vendorPaymentMethod = result.getValue({ name: "custrecord_ven_pymt_methods" }); log.debug('Search Result', vendorPaymentMethod); return false; // Stop after the first result }); return vendorPaymentMethod;}return {
fieldChanged: fieldChanged
};
});