I am attempting to use a Script to add item thumbn...
# suitescript
g
I am attempting to use a Script to add item thumbnail images to our Estimate and Invoice Advanced PDFs.  I found this SuiteAnswer article that shows how to do it but I keep getting a "That record does not exist. path:" system error.  I do get the correct URL to log to Debug but I can't find out what is causing the error. This is the code I am using as a USER EVENT that executes BEFORE SUBMIT FUNCTION:
Copy code
function getURLfromItem(type){
        var itemCount = nlapiGetLineItemCount('item');

        for (var i=1;i<=itemCount;i++)
        {
                nlapiSelectLineItem('item', i);
                var itemId = nlapiGetCurrentLineItemValue('item','item');
                var thumbnailUrl = nlapiLookupField('item',itemId,'custitem84');
                  var file = nlapiLoadFile(thumbnailUrl);
                  var imageUrl = file.getURL();
                  var completeUrl = '<https://system.netsuite.com>' + imageUrl;
                nlapiSetCurrentLineItemValue('item', 'custcol_item_thumbnail_url', completeUrl, true, true);
                nlapiCommitLineItem('item');
                  nlapiLogExecution('DEBUG','URL', completeUrl);
        }
}
The error occurs when trying to save a new estimate so that the script executes and generates the correct image URL. What am I missing? Please help!
b
you probably want to take a look at the stack trace to see what line the error is on
but the guess is that thumbnailUrl is not what you expect it is
you should also be weary about the performance cost associated with this kind of script, it does a lookup and file load for every line of your transaction
if you have lots of lines, you may notice the performance impact
consider doing one search to get the 'custitem84 of all your line items at the same time
and potentially one file search to get all the urls
g
@battk How do I access the stack trace? Sorry, I am extremely new to everything NetSuite. I thought the DEBUG log would provide more details than it does.
b
catch the error and log the stack or stackTrace key using the suitescript debugger can also help, though its much work work to learn
errors in suitescript 1 tend to be harder to work with than errors in suitescript 2
so you may want to consider using suitescript 2 instead
g
@battk Thanks for the help. I believe I found the issue. It is breaking because the 4th and 5th items in the estimate are not inventory items with thumbnail images. I think I need to include an if-else statement in the for loop to check for this but unsure which is best practice. Check for a thumbnail existing or check for item type <itemtype>InvtPart</itemtype> vs <itemtype>Service</itemtype> or any other type.