Search code examples
netsuite

Run After Submit Script when approve button is clicked Netsuite


When approve button is clicked on journal entry, this reversal should be auto approved. This script is running when i am clicking edit and then saving. I want this to run when just approve button is clicked without editing. How can i do that?

    function JEReversalAfterSubmit(type){

    if (type == 'approve')
   {
            var filters2 = new Array();
            filters2[0] = new nlobjSearchFilter( 'tranid', null, 'is', 'JV267');
            var columns2 = new Array();
            columns2[0] = new nlobjSearchColumn( 'internalid' );
            var searchresults2 = nlapiSearchRecord( 'journalentry', null, filters2, columns2 );

            for ( var j = 0; searchresults2 != null && j < searchresults2.length; j++ )
            {
                var searchresult2 = searchresults2[ j ];
                var reversalJEID = searchresult2.getValue( 'internalid' );
                nlapiLogExecution('debug','reversalJEID',reversalJEID);
            }

            nlapiLogExecution('DEBUG','34','34');

            var params = new Array();
            params['type'] = 'approve';
            nlapiSetRedirectURL('RECORD','journalentry',reversalJEID, 'false',params);
        }
      }
    }

    }

Solution

  • How is the approve button created? If it is created via workflow, you can use a custom workflow action script for this instead of an User Event script.