I’m adding a custom ship to address from a client ...
# suitescript
j
I’m adding a custom ship to address from a client script on a Sales Order. How can I make the change trigger sales tax re-evaluation.
b
what does the code look like
j
/**
*@NApiVersion 2.x *@NScriptType ClientScript */ define( [ ‘SuiteScripts/Globals/DAO/daoLocation’, ‘N/ui/dialog’, ], function(daoLocation,dialog) { function pageInit(context) { } function fieldChanged(context) { var currentRecord = context.currentRecord; var _fieldId = context.fieldId; var fieldValue = currentRecord.getValue(_fieldId); if (_fieldId == ‘custbody_pl_storepickup’) { var intLocationId = currentRecord.getValue(‘location’); if(intLocationId == ‘’) { alert(‘Pick a store first.’); currentRecord.setValue({ fieldId: ‘custbody_pl_storepickup’, value: false, ignoreFieldChange: true, forceSyncSourcing: true }); } else { if(fieldValue == true) { var objLocation = daoLocation.getObj(intLocationId); if(objLocation.taxItemId != ‘’) { currentRecord.setValue({ fieldId: ‘shipaddresslist’, value: -2, // -2 == - Custom - ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘attention’, value: ‘Store Pick Up ’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘addr1’, value: objLocation.address1, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘addr2’, value: objLocation.address2, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘city’, value: objLocation.city, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘state’, value: objLocation.state, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘zip’, value: objLocation.zip, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘country’, value: objLocation.country, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘shipaddress’, value: ‘Store Pick Up ’ + ' ' + objLocation.address1 + ' ' + objLocation.city + ' ' + objLocation.state + ' ' + objLocation.zip + ' ' + objLocation.country, forceSyncSourcing: true, ignoreFieldChange: false }); } } else { currentRecord.setValue({ fieldId: ‘shipaddresslist’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘attention’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘addr1’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘addr2’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘city’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘state’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘zip’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘country’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); var boIsTaxable = currentRecord.getValue(‘isTaxable’); if(boIsTaxable) { currentRecord.setValue({ fieldId: ‘taxitem’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); currentRecord.setValue({ fieldId: ‘taxrate’, value: ‘’, ignoreFieldChange: true, forceSyncSourcing: true }); } currentRecord.setValue({ fieldId: ‘shipaddress’, value: ‘’, forceSyncSourcing: true }); dialog.alert({title: ‘ALERT!’, message: ‘Since you selected Store Pick Up then unselected this option - you will have to reselect the desireed ship to address for this order.’}); } } } } return { pageInit : pageInit, fieldChanged : fieldChanged }; });
b
you need to use the address subrecord
keep in mind that editing subrecords is not officially supported in suitescript 2, though it will work for addresses
j
Great thanks! I don’t mind grinding it out but just wanted to make sure I’m not wasting time.
b
you also probably want to stop setting ignoreFieldChange if you want sourcing to work