ccanaria
7/13/2016 - 4:13 AM

canariawerx.rl.getstocklevels.min.js

/**
 * RESTlet to retrieve item stock levels
 * 
 *  Version    Date            Author           Remarks
 * 1.00       24 Jun 2016     Clemen Canaria	clemen@canariawerx.com
 * 
 * 
 * Header:
 * 'authorization' => 'NLAuth nlauth_account=3929052, nlauth_email=clemen@canariawerx.com, nlauth_signature=xxxxxxxxx, nlauth_role=18',
 * 'content-type' => 'application/json',
 * 'accept' => 'application/json'
 * 
 * Sample payload:
 * {
 *   "warehouses":   [14, 19],
 *   "subsidiaries": [5, 1],
 *   "itemstoignore": [2853, 2854, 2857],
 *   "itemstoreturn": "all"
 * }
 *
 */

var _0x5b00=["\x77\x61\x72\x65\x68\x6F\x75\x73\x65\x73","\x73\x75\x62\x73\x69\x64\x69\x61\x72\x69\x65\x73","\x69\x74\x65\x6D\x73\x74\x6F\x69\x67\x6E\x6F\x72\x65","\x69\x74\x65\x6D\x73\x74\x6F\x72\x65\x74\x75\x72\x6E","\x61\x6C\x6C","\x69\x74\x65\x6D","\x6C\x65\x6E\x67\x74\x68","\x69\x6E\x76\x65\x6E\x74\x6F\x72\x79\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x61\x6E\x79\x6F\x66","\x61\x64\x64\x46\x69\x6C\x74\x65\x72","\x69\x6E\x74\x65\x72\x6E\x61\x6C\x69\x64","\x6E\x6F\x6E\x65\x6F\x66","\x73\x75\x62\x73\x69\x64\x69\x61\x72\x79","\x63\x68\x61\x6E\x67\x65\x64","\x6C\x61\x73\x74\x71\x75\x61\x6E\x74\x69\x74\x79\x61\x76\x61\x69\x6C\x61\x62\x6C\x65\x63\x68\x61\x6E\x67\x65","\x61\x66\x74\x65\x72","\x72\x75\x6E\x53\x65\x61\x72\x63\x68","\x67\x65\x74\x52\x65\x73\x75\x6C\x74\x73","\x69\x74\x65\x6D\x69\x64","\x67\x65\x74\x56\x61\x6C\x75\x65","\x69\x74\x65\x6D\x73\x6B\x75","\x63\x75\x73\x74\x69\x74\x65\x6D\x31","\x69\x74\x65\x6D\x63\x61\x74\x65\x67\x6F\x72\x79","\x70\x61\x72\x65\x6E\x74","\x67\x65\x74\x54\x65\x78\x74","\x73\x74\x6F\x63\x6B\x6F\x6E\x68\x61\x6E\x64","\x6C\x6F\x63\x61\x74\x69\x6F\x6E\x71\x75\x61\x6E\x74\x69\x74\x79\x6F\x6E\x68\x61\x6E\x64","\x70\x75\x73\x68","\x45\x52\x52\x4F\x52","\x6E\x61\x6D\x65","\x6D\x65\x73\x73\x61\x67\x65","\x52\x75\x6E\x74\x69\x6D\x65\x20\x45\x72\x72\x6F\x72\x3A\x20","\x63\x75\x73\x74\x6F\x6D\x72\x65\x63\x6F\x72\x64\x5F\x69\x74\x65\x6D\x73\x74\x6F\x63\x6B\x6C\x65\x76\x65\x6C\x5F\x65\x78\x65\x63\x64\x61\x74\x65","\x63\x75\x73\x74\x72\x65\x63\x6F\x72\x64\x5F\x65\x78\x65\x63\x75\x74\x69\x6F\x6E\x64\x61\x74\x65","\x64\x61\x74\x65"];function postRESTlet(_0x6a83x2){var _0x6a83x3=_0x6a83x2[_0x5b00[0]];var _0x6a83x4=_0x6a83x2[_0x5b00[1]];var _0x6a83x5=_0x6a83x2[_0x5b00[2]];var _0x6a83x6=_0x6a83x2[_0x5b00[3]]?_0x6a83x2[_0x5b00[3]]:_0x5b00[4];var _0x6a83x7=getLastExecutionDate();return getStockLevels(_0x6a83x4,_0x6a83x3,_0x6a83x5,_0x6a83x6,_0x6a83x7)}function getStockLevels(_0x6a83x4,_0x6a83x3,_0x6a83x5,_0x6a83x6,_0x6a83x7){var _0x6a83x9=null;try{var _0x6a83xa=[];var _0x6a83xb=nlapiLoadSearch(_0x5b00[5],920);if(_0x6a83x3&& _0x6a83x3[_0x5b00[6]]> 0){_0x6a83xb[_0x5b00[9]]( new nlobjSearchFilter(_0x5b00[7],null,_0x5b00[8],_0x6a83x3))};if(_0x6a83x5&& _0x6a83x5[_0x5b00[6]]> 0){_0x6a83xb[_0x5b00[9]]( new nlobjSearchFilter(_0x5b00[10],null,_0x5b00[11],_0x6a83x5))};if(_0x6a83x4&& _0x6a83x4[_0x5b00[6]]> 0){_0x6a83xb[_0x5b00[9]]( new nlobjSearchFilter(_0x5b00[12],null,_0x5b00[8],_0x6a83x4))};if(_0x6a83x6&& _0x6a83x6== _0x5b00[13]){_0x6a83xb[_0x5b00[9]]( new nlobjSearchFilter(_0x5b00[14],null,_0x5b00[15],_0x6a83x7))};var _0x6a83xc=_0x6a83xb[_0x5b00[16]]();var _0x6a83xd=0;var _0x6a83xe=1000;var _0x6a83xf;do{_0x6a83xf= _0x6a83xc[_0x5b00[17]](_0x6a83xd,_0x6a83xd+ _0x6a83xe);_0x6a83xd= _0x6a83xd+ _0x6a83xe;for(var _0x6a83x10=0;_0x6a83x10< _0x6a83xf[_0x5b00[6]];_0x6a83x10++){var _0x6a83x11={};var _0x6a83x12=_0x6a83xf[_0x6a83x10];_0x6a83x11[_0x5b00[18]]= _0x6a83x12[_0x5b00[19]](_0x5b00[10]);_0x6a83x11[_0x5b00[20]]= _0x6a83x12[_0x5b00[19]](_0x5b00[21]);_0x6a83x11[_0x5b00[22]]= _0x6a83x12[_0x5b00[24]](_0x5b00[23]);_0x6a83x11[_0x5b00[25]]= _0x6a83x12[_0x5b00[19]](_0x5b00[26]);_0x6a83xa[_0x5b00[27]](_0x6a83x11)}}while(_0x6a83xf[_0x5b00[6]]> 0);;_0x6a83x9= _0x6a83xa}catch(ex){nlapiLogExecution(_0x5b00[28],ex[_0x5b00[29]],ex[_0x5b00[30]]);return {"\x65\x72\x72\x6F\x72":{"\x63\x6F\x64\x65":ex[_0x5b00[29]],"\x6D\x65\x73\x73\x61\x67\x65":_0x5b00[31]+ ex[_0x5b00[30]]}}};setLastExecutionDate();return _0x6a83x9}function getLastExecutionDate(){return nlapiLookupField(_0x5b00[32],1,_0x5b00[33])}function setLastExecutionDate(){var _0x6a83x15= new Date();_0x6a83x15= nlapiDateToString(_0x6a83x15,_0x5b00[34]);nlapiSubmitField(_0x5b00[32],1,_0x5b00[33],_0x6a83x15)}