There are instances when a user would like to have a the reverse journal entry automatically approved upon creating a pending approval journal entry.
This use case could be met by creating a user event script triggered on after submit, such as the script below:
function afterSubmit(type){
var journalID = nlapiGetRecordId();
var filters = new Array();
filters[0] = new nlobjSearchFilter( 'internalid', null, 'is', journalID);
var columns = new Array();
columns[0] = new nlobjSearchColumn( 'reversalnumber' );
var searchresults = nlapiSearchRecord( 'journalentry', null, filters, columns );
for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
{
var searchresult = searchresults[ i ];
var reversalJE = searchresult.getValue( 'reversalnumber' );
nlapiLogExecution('debug','reversalJE',reversalJE);
}
var filters2 = new Array();
filters2[0] = new nlobjSearchFilter( 'tranid', null, 'is', reversalJE);
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);
}
var params = new Array();
params['type'] = 'approve';
nlapiSetRedirectURL('RECORD','journalentry',reversalJEID, 'false',params);
}
No comments:
Post a Comment