This topic contains 3 replies, has 0 voices, and was last updated by Tedward 8 years, 6 months ago.
-
AuthorPosts
-
May 12, 2016 at 10:00 am #6692
TedwardHoping someone can point me in the right direction as I’m at a total loss right now..
I’m looking for a way to pull PDF copies of UI created invoices, preferably straight from the invoice record on demand but I’d settle for some way to send it to the file cabinet (on save maybe) and I pull it from there. I’m sure I could figure out downloading file cabinet files (pretty sure I have sample code for that) if I can just get it there in the first place.
Any help would be greatly appreciated
Ted
This is a cached copy. Click here to see the original post. -
May 12, 2016 at 11:37 am #6693
samzadCan’t you just use the print function?
Otherwise use a userevent script to invoke nlapiPrintRecord to create PDF of the invoice and push it to file cabinet when the invoice is saved/approved.
-
May 12, 2016 at 12:03 pm #6694
TedwardSorry I should have specified I need this to happen without additional user action (i.e. don’t want to rely on them using print and manually moving the pdf someplace specific), which is why I was hoping for a web services option.
nlapiPrintRecord looks promising though, thanks for the tip. I’ll report back with where I wind up.
-
May 12, 2016 at 4:54 pm #6695
TedwardThis is what I’ve come up with. Forewarning I have not done a ton of testing, I have not built in much in the way of error catching yet, and some of this was obviously new to me and learning as I went, so use my code at your own risk etc. On that note any feedback on cleaning up or improving my code would also be appreciated.
First I have a custom check box on customers called ‘Generate Invoice’, and the same thing on my invoices which sources in from customers, invoice version of it has the id ‘custbody_generate_invoice’. I have a folder in my file cabinet with internal ID 1856.
You’ll also notice I pull a custom field off the invoice called route_for_customer, which I pass along in the files description in order to create a sub folder at the end.
This first code is a scheduled script I have running every 15 minutes, it pulls all invoices flagged to generate dated next day or before, names the invoices ‘Invoice# – Customer name’ i.e. ‘409463 – Walmart #3191’ and dumps them to the file cabinet.
Code:
function main(){
var d = new Date();
d.setDate(d.getDate() + 1); //Tomorrow
// Define search filters
var filters = new Array();
filters[0] = new nlobjSearchFilter( ‘custbody_generate_invoice’, null, ‘is’, ‘T’ );
filters[1] = new nlobjSearchFilter( ‘trandate’, null, ‘onorbefore’, (d.getMonth() + 1) + “/” + d.getDate() + “/” + d.getFullYear());
filters[2] = new nlobjSearchFilter( ‘type’, null, ‘is’, ‘CustInvc’ );
filters[3] = new nlobjSearchFilter( ‘mainline’, null, ‘is’, ‘T’ );
// Define search columns
var columns = new Array();
columns[0] = new nlobjSearchColumn( ‘internalid’ );
columns[1] = new nlobjSearchColumn( ‘tranid’ );
columns[2] = new nlobjSearchColumn( ‘entity’ );
columns[3] = new nlobjSearchColumn( ‘custbody_route_for_customer’ );
// Create search
var searchresults = nlapiSearchRecord( ‘transaction’, null, filters, columns );for(var i = 0; searchresults != null && i < searchresults.length; i++){
var file = nlapiPrintRecord('transaction', searchresults[i].getValue('internalId'), 'PDF', null);
file.setFolder(1856);
file.setName(searchresults[i].getValue('tranid') + " – " + searchresults[i].getText('entity') + ".pdf");
file.setDescription(searchresults[i].getText('custbody_route_for_customer'));
var id = nlapiSubmitFile(file);
if(id != null){
nlapiSubmitField('invoice', searchresults[i].getValue('internalId'), 'custbody_generate_invoice', 'F');
}
}
}
This second code uses the php toolkit and runs off my server also every 15 minutes, staggered a few minutes behind the first one to give it time to run. It pulls all invoices from the file cabinet, downloads them, saves them in subfolders according to the file description field, removes any garbage from the file name so I don't wind up with illegal file names because of customer name info, and deletes all saved files out of the file cabinet.PHP Code:
folder = new SearchMultiSelectField();
$search->folder->operator = “anyOf”;
$search->folder->searchValue = array();$search->folder->searchValue[0] = new RecordRef();
$search->folder->searchValue[0]->type = ‘folder’;
$search->folder->searchValue[0]->internalId = 1856;$request = new SearchRequest();
$request->searchRecord = $search;$searchResponse = $service->search($request);
if (!$searchResponse->searchResult->status->isSuccess) {
echo “Search Error”;
} else {
$i = 0;
foreach($searchResponse->searchResult->recordList->record as $file){
echo “$file->internalIdn”;
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = $file->internalId;
$request->baseRef->type = “file”;
$getResponse = $service->get($request);
if (!$getResponse->readResponse->status->isSuccess) {
echo ” – GET ERROR”;
} else {
$file = $getResponse->readResponse->record;
if(!is_dir(“C:\invoices from netsuite” . $file->description)){ mkdir(“C:\invoices from netsuite” . $file->description); }
file_put_contents(“C:\invoices from netsuite” . $file->description . “” . mb_ereg_replace(“([^wsd-_~,;[]().])”, ”, $file->name), $file->content);
$deleteList[$i] = new RecordRef();
$deleteList[$i]->internalId = $file->internalId;
$deleteList[$i]->type = ‘file’;
$i++;
}
}
$request = new deleteListRequest();
$request->baseRef = $deleteList;
$service->deleteList($request, null);
}?>
-
AuthorPosts
You must be logged in to reply to this topic.