Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @NAPIVersion 2.x
- * @NScriptType UserEventScript
- */
- // nama: ABA - Bill Credit UE
- // id: aba_vendcred_ue
- // func: Set Default Bill Credit Value on Form
- // by: Dio Pratama, 2020
- define(["N/record"], function (record) {
- function beforeSubmit(context) {
- var rec = context.newRecord;
- try {
- if (context.type == context.UserEventType.CREATE || context.type == context.UserEventType.EDIT) {
- log.debug({
- "title": "check: record",
- "details": rec
- });
- var recType = rec.type;
- var FormID = rec.getValue({
- fieldId: 'customform'
- });
- log.debug({
- "title": "check: recType - FormID",
- "details": recType + " - " + FormID
- });
- var trxId = rec.getValue({
- fieldId: 'id'
- });
- log.debug({
- "title": "check: trx.id",
- "details": trxId
- });
- if (recType == 'vendorcredit') {
- if (null == rec.getValue({
- fieldId: 'cseg_aba_sgmt_slch'
- })
- || rec.getValue({
- fieldId: 'cseg_aba_sgmt_slch'
- }) == '') {
- rec.setValue('cseg_aba_sgmt_slch', 5, true);
- }
- //-----------------------------------------------------------------------------
- var numItemLines = rec.getLineCount({
- sublistId: 'item'
- });
- for (var i = 0; i < numItemLines; i++) {
- if (rec.getSublistValue({
- sublistId: 'item',
- fieldId: 'item',
- line: i
- }) != ''
- && (null == rec.getSublistValue({
- sublistId: 'item',
- fieldId: 'cseg_aba_sgmt_slch',
- line: i
- })
- || rec.getSublistValue({
- sublistId: 'item',
- fieldId: 'cseg_aba_sgmt_slch',
- line: i
- }) == '')) {
- rec.setSublistValue({
- sublistId: 'item',
- fieldId: 'cseg_aba_sgmt_slch',
- line: i,
- value: 5
- });
- }
- }
- //-----------------------------------------------------------------------------
- var numExpLines = rec.getLineCount({
- sublistId: 'expense'
- });
- for (var j = 0; j < numExpLines; j++) {
- if (rec.getSublistValue({
- sublistId: 'expense',
- fieldId: 'account',
- line: j
- }) != ''
- && (null == rec.getSublistValue({
- sublistId: 'expense',
- fieldId: 'cseg_aba_sgmt_slch',
- line: j
- })
- || rec.getSublistValue({
- sublistId: 'expense',
- fieldId: 'cseg_aba_sgmt_slch',
- line: j
- }) == '')) {
- rec.setSublistValue({
- sublistId: 'expense',
- fieldId: 'cseg_aba_sgmt_slch',
- line: j,
- value: 5
- });
- }
- }
- //-----------------------------------------------------------------------------
- } //
- }
- } //
- catch (e) {
- log.error({
- "title": "Error",
- "details": e.toString()
- });
- try {
- return 'Please try again... ' + e.toString();
- } catch (e) {
- log.error({
- "title": "Error",
- "details": e.toString()
- });
- return e.toString();
- }
- }
- }
- return {
- beforeSubmit: beforeSubmit
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment