We have a custom script that an ex-employee wrote,...
# general
a
We have a custom script that an ex-employee wrote, which looks for newly created inventory items, and pushes their Internal ID, UPC Code, and Name to another database we use in our warehouse. This script typically runs no problem, but last night it errored out with the following message:
Invalid data format. You should return text.
I've looked at the inventory items that were supposed to be pushed to that database last night, and at a glance they look identical to all the other items that have successfully gone through. Any ideas?
Copy code
function getGTIN()
{
    var gtin_records = [];
    var searchresults = nlapiSearchRecord('inventoryitem', 'customsearch_cofe_getgtin');

    // return search results             
    for ( var i = 0; searchresults != null && i < searchresults.length; i++ )
    {
        var currentresult = new Object();
        currentresult.nsid = searchresults[i].getValue(nlobjSearchColumn('internalid', null, null));
        currentresult.gtin = searchresults[i].getValue(nlobjSearchColumn('upccode', null, null));
        currentresult.description = searchresults[i].getValue(nlobjSearchColumn('name', null, null));    
        gtin_records.push(currentresult);
    }

    var results = new Object();
    results.records = gtin_records;
    return results;
}
b
Notes about RESTlet Errors describes this error
your error is a description of what happens when your Content-Type header is wrong
a
@battk thanks, from what first link, it appears the issue is "If users provide data in a format different from specified type, the following error is returned with one of the following messages:" however I'm not sure why it's not interpreting the data as text when it is. This is the saved search that's referenced in line 3 called
customsearch_cofe_getgtin
b
read both links
the search content has nothing to do with the content type header
nor the return value of your restlet
a
where would I specify the HTTP Content Type header? This is the url /app/site/hosting/restlet.nl?script=109&deploy=1
b
thats up to whatever is sending the http request
an http request includes multiple parts
both the url and the headers are different parts
a
Sorry i think I'm a bit lost on that last part. I'm initiating this directly through the Script Deployment screen for this script.
b
if you are doing this in a browser window, then you aren't sending any content type and its defaulting to plaintext
a
Since I'm relatively new to suite scripting and trying to decipher code written by long gone employees, how would a RESTlet script run if not scheduled and not through the browser?
Thank you for the help, I'm just a bit lost on what you mean by content type header
b
there is another piece that you are missing
something that is making the http request to your restlet
it probably isnt in netsuite
a
yeah that makes sense. Unfortunately our WMS is completely custom built and I'm trying to reverse engineer this script that's causing so many issues