Hello All, I'm trying to implement the interim wor...
# suitescript
d
Hello All, I'm trying to implement the interim workaround on vendor bill approvals for roles that donot have override period restriction permission mentioned in suiteanswers article https://suiteanswers.custhelp.com/app/answers/detail/a_id/97841/loc/en_US. The issue here is "A Vendor Bill record is approved and then posts on a locked period while the role used by the approver does not have override period restriction permission. The expected result is that the approved vendor bill posts on the next open accounting period." The code in the article doesn't seem to work. Solution steps from the SA Article The interim workaround is a script deployment. The script detects posting of an approved Vendor Bill record on a locked period, and then performs the following: • Change the posting period to the next open accounting period. • Change the Date field value to the first day of the next open accounting period. • Retain the Due Date field value. Solution Steps 1. Copy the following script 2. Save as a Java script file in your local folder 3. function afterSubmit(type) {‌ 4. var APPROVED_STATUS = 2; 5. var TYPE_SUPPORTED = ['create', 'copy', 'edit', 'xedit']; 6. 7. if (TYPE_SUPPORTED.indexOf(type.toLowerCase()) > -1) {‌ 8. var oldApprovalStatus = ''; 9. if (type === 'edit' || type === 'xedit') {‌ 10. var oldRecord = nlapiGetOldRecord(); 11. oldApprovalStatus = oldRecord.getFieldValue('approvalstatus') || ''; 12. } 13. 14. var newRecord = nlapiGetNewRecord(); 15. var newApprovalStatus = newRecord.getFieldValue('approvalstatus') || ''; 16. 17. if ( 18. oldApprovalStatus !== newApprovalStatus && 19. +newApprovalStatus === APPROVED_STATUS 20. ) {‌ 21. setPostingPeriod(); 22. } 23. } 24. } 25. 26. function setPostingPeriod() {‌ 27. try {‌ 28. nlapiLogExecution('debug', 'Set Posting Period', 'START'); 29. var stType = nlapiGetRecordType(); 30. stType = stType.toUpperCase(); 31. 32. if (stType === 'VENDORBILL') {‌ 33. var stpostPeriod = nlapiGetFieldValue('postingperiod'); 34. var stSubsidiary = nlapiGetFieldValue('subsidiary'); 35. var stRecordId = nlapiGetRecordId(); 36. 37. if (!stpostPeriod) {‌ 38. var objRec = nlapiLoadRecord(stType, stRecordId); 39. stpostPeriod = objRec.getFieldValue('postingperiod'); 40. stSubsidiary = objRec.getFieldValue('subsidiary'); 41. } 42. 43. var objResults = nlapiSearchRecord( 44. 'accountingperiod', 45. null, 46. [ 47. new nlobjSearchFilter( 48. 'internalidnumber', 49. null, 50. 'greaterthanorequalto', 51. stpostPeriod 52. ), 53. new nlobjSearchFilter('aplocked', null, 'is', 'F'), 54. new nlobjSearchFilter('isquarter', null, 'is', 'F') 55. ], 56. new nlobjSearchColumn('internalid').setSort() 57. ); 58. for (var i = 0; i < objResults.length; i++) {‌ 59. var stPeriod = objResults[i].getId(); 60. var arrFilters = []; 61. arrFilters.push( 62. new nlobjSearchFilter('itemtype', null, 'anyof', [ 63. 'PCP_LOCK_AP' 64. ]) 65. ); 66. arrFilters.push( 67. new nlobjSearchFilter('period', null, 'abs', stPeriod) 68. ); 69. if (stSubsidiary) 70. arrFilters.push( 71. new nlobjSearchFilter('subsidiary', null, 'anyof', [ 72. stSubsidiary 73. ]) 74. ); 75. 76. var objSearchPeriod = nlapiSearchRecord( 77. 'taskitemstatus', 78. null, 79. arrFilters, 80. new nlobjSearchColumn('complete') 81. ); 82. var bResultFound = false; 83. if (objSearchPeriod) {‌ 84. if (objSearchPeriod.length > 0) {‌ 85. var bComplete = objSearchPeriod[0].getValue('complete'); 86. nlapiLogExecution( 87. 'error', 88. 'Set Posting Period', 89. 'bComplete: ' + bComplete 90. ); 91. if (bComplete !== 'T') {‌ 92. nlapiLogExecution( 93. 'debug', 94. 'Set Posting Period', 95. 'bComplete!==T > stPeriod: ' + stPeriod 96. ); 97. setTransactionDate(stPeriod, stType, stRecordId); 98. break; 99. } 100. bResultFound = true; 101. } 102. } 103. if (!bResultFound) {‌ 104. nlapiLogExecution( 105. 'debug', 106. 'Set Posting Period', 107. '!bResultFound > stPeriod: ' + stPeriod 108. ); 109. setTransactionDate(stPeriod, stType, stRecordId); 110. break; 111. } 112. } 113. } 114. nlapiLogExecution('debug', 'Set Posting Period', 'FINISH'); 115. } catch (error) {‌ 116. nlapiLogExecution('error', 'Set Posting Period', error.toString()); 117. } 118. } 119. 120. function setTransactionDate(stPeriod, stType, stRecordId) {‌ 121. var objAcctgPeriod = nlapiLoadRecord('accountingperiod', stPeriod); 122. var stPeriodStartDate = objAcctgPeriod.getFieldValue('startdate'); 123. var stDueDate = nlapiGetFieldValue('duedate'); 124. nlapiSubmitField(stType, stRecordId, ['trandate','duedate'], [stPeriodStartDate, stDueDate]); 125. } The above solution doesn't seem to work. any thoughts??
c
When you say "doesn't seem to work", what do you mean? Have you checked that it's executing at all & posting debug information to the logs? If it is executing, what is/isn't it doing wrong?
d
@CD I see the script is triggering. However I see the following error in execution logs "DETAILS Code: USER_ERROR Details: Please enter value(s) for: Invoice Date"