Created
July 12, 2019 00:10
-
-
Save cafeasp/20d2b34f210cf30c2e8a4946ee848ea4 to your computer and use it in GitHub Desktop.
NetSuite - Create Customer Deposit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CreateCustomerDeposit(salesOrderId, paymentMethod) { | |
try { | |
if (paymentMethod != 'free') { | |
var order = record.load({ | |
id: salesOrderId, | |
type: record.Type.SALES_ORDER, | |
isDynamic: true | |
}); | |
var total = order.getValue({ | |
fieldId: 'total' | |
}); | |
log.debug('sales order total', total); | |
var oDate = order.getValue({ | |
fieldId: 'trandate' | |
}); | |
if (total > 0) { | |
var customerDeposit = record.create({ | |
type: record.Type.CUSTOMER_DEPOSIT, | |
isDynamic: true, | |
defaultValues: { | |
entity: 123, | |
salesorder: salesOrderId | |
} | |
}); | |
customerDeposit.setValue({ fieldId: 'department', value: 509999 }); | |
customerDeposit.setValue({ fieldId: 'class', value: 18000 }); | |
customerDeposit.setValue({ fieldId: 'payment', value: total }); | |
switch (paymentMethod) { | |
case "credit_card": | |
customerDeposit.setValue({ fieldId: 'account', value: '123' }); | |
break; | |
case "paypal_express": | |
customerDeposit.setValue({ fieldId: 'account', value: '123' }); | |
break; | |
} | |
customerDeposit.setValue({ fieldId: 'trandate', value: new Date(oDate) }); | |
var id = customerDeposit.save({ | |
enableSourcing: false, | |
ignoreMandatoryFields: false | |
}); | |
log.debug('deposit id', id); | |
} | |
} else { | |
log.debug('customer deposit', 'skip'); | |
} | |
} catch (error) { | |
log.debug('error-customer deposit', error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment