Dio64

VendCred_ue.js

Jul 1st, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. /**
  2. * @NAPIVersion 2.x
  3. * @NScriptType UserEventScript
  4. */
  5. // nama: ABA - Bill Credit UE
  6. // id: aba_vendcred_ue
  7. // func: Set Default Bill Credit Value on Form
  8. // by: Dio Pratama, 2020
  9. define(["N/record"], function (record) {
  10. function beforeSubmit(context) {
  11. var rec = context.newRecord;
  12. try {
  13. if (context.type == context.UserEventType.CREATE || context.type == context.UserEventType.EDIT) {
  14. log.debug({
  15. "title": "check: record",
  16. "details": rec
  17. });
  18.  
  19. var recType = rec.type;
  20. var FormID = rec.getValue({
  21. fieldId: 'customform'
  22. });
  23. log.debug({
  24. "title": "check: recType - FormID",
  25. "details": recType + " - " + FormID
  26. });
  27.  
  28. var trxId = rec.getValue({
  29. fieldId: 'id'
  30. });
  31. log.debug({
  32. "title": "check: trx.id",
  33. "details": trxId
  34. });
  35.  
  36. if (recType == 'vendorcredit') {
  37. if (null == rec.getValue({
  38. fieldId: 'cseg_aba_sgmt_slch'
  39. })
  40. || rec.getValue({
  41. fieldId: 'cseg_aba_sgmt_slch'
  42. }) == '') {
  43. rec.setValue('cseg_aba_sgmt_slch', 5, true);
  44. }
  45.  
  46. //-----------------------------------------------------------------------------
  47. var numItemLines = rec.getLineCount({
  48. sublistId: 'item'
  49. });
  50.  
  51. for (var i = 0; i < numItemLines; i++) {
  52. if (rec.getSublistValue({
  53. sublistId: 'item',
  54. fieldId: 'item',
  55. line: i
  56. }) != ''
  57. && (null == rec.getSublistValue({
  58. sublistId: 'item',
  59. fieldId: 'cseg_aba_sgmt_slch',
  60. line: i
  61. })
  62. || rec.getSublistValue({
  63. sublistId: 'item',
  64. fieldId: 'cseg_aba_sgmt_slch',
  65. line: i
  66. }) == '')) {
  67. rec.setSublistValue({
  68. sublistId: 'item',
  69. fieldId: 'cseg_aba_sgmt_slch',
  70. line: i,
  71. value: 5
  72. });
  73. }
  74. }
  75.  
  76. //-----------------------------------------------------------------------------
  77. var numExpLines = rec.getLineCount({
  78. sublistId: 'expense'
  79. });
  80.  
  81. for (var j = 0; j < numExpLines; j++) {
  82. if (rec.getSublistValue({
  83. sublistId: 'expense',
  84. fieldId: 'account',
  85. line: j
  86. }) != ''
  87. && (null == rec.getSublistValue({
  88. sublistId: 'expense',
  89. fieldId: 'cseg_aba_sgmt_slch',
  90. line: j
  91. })
  92. || rec.getSublistValue({
  93. sublistId: 'expense',
  94. fieldId: 'cseg_aba_sgmt_slch',
  95. line: j
  96. }) == '')) {
  97. rec.setSublistValue({
  98. sublistId: 'expense',
  99. fieldId: 'cseg_aba_sgmt_slch',
  100. line: j,
  101. value: 5
  102. });
  103. }
  104. }
  105.  
  106. //-----------------------------------------------------------------------------
  107. } //
  108. }
  109.  
  110. } //
  111. catch (e) {
  112. log.error({
  113. "title": "Error",
  114. "details": e.toString()
  115. });
  116. try {
  117. return 'Please try again... ' + e.toString();
  118. } catch (e) {
  119. log.error({
  120. "title": "Error",
  121. "details": e.toString()
  122. });
  123. return e.toString();
  124. }
  125. }
  126. }
  127.  
  128. return {
  129. beforeSubmit: beforeSubmit
  130. };
  131. });
Advertisement
Add Comment
Please, Sign In to add comment