We have a Suiteflow that sends an email as an attachment. However, the email doesn't send if the attachment is over 5 MB in size. I want to add a condition to the action that says when document size is < 5 MB. I planned on then adding a separate action to send the email without the attachment if the file size is >= 5 MB. Is this possible and if not, what work around is there?
SuiteScript (Javascript) is certainly an option but I would prefer just modifying the existing SuiteFlow
::In Response to below comments:
The email attachment is added to a Document field on the Transaction, not in the File subtab. I cannot find how to get at it's properties (like size) therefore in a search. (idea #2 below).
Also, the code sample (idea #1) does not work because nlapiLoadFile will not load a file > 5 mb, meaning I can't do a test etc. I am trying to avoid writing the whole thing as a script.
So far the only solution (and I don't feel it is a good one) is to take the sending of the email, make it into a script, and do a try catch on it. Any other ideas??
Assuming that the file that you are sending as an attachment is a file that already exists in Netsuite file cabinet you can add a script to validate the size of the attachment:
var load = nlapiLoadFile('100');//where 100 is the internal id of the file
var filesize = load.getSize(); //Returns the size of the file in bytes
if(filesize > .....) //
For reference of using this Suitescript API:
Helpguide > SuiteCloud (Customization, Scripting, and Web Services) : SuiteScript : SuiteScript API : SuiteScript Objects : nlobjFile
I konw its not efficient but how about doing a search to get the size of the file. Something like this
Filters:
Internal Id = internal id of the attachment
Results:
Size
The Size column would return the file size in KB.
Related
I'm configuring some requests programmatically in my test cases, I can set headers, custom properties, teardown scripts, etc. however I can't find how to set a standard json body for my put requests.
Is there any possibility from the restMethod class ?
So far I end up getting the method used :
restService = testRunner.testCase.testSuite.project.getInterfaceAt(0)
resource = restService.getOperationByName(resource_name)
request = resource.getRequestAt(0)
httpMethod = request.getMethod()
if (httpMethod.toString().equals("PUT"))
but then I'm stuck trying to find how to set a standard body for my PUT requests.
I try with the getRequestParts() method but it didn't give me what I expected ...
can anyone help, please
thank you
Alexandre
I’ve managed this. I had a tests of tests where I wanted to squirt the content of interest into the “bare bones” request. Idea being that I can wrap this in a data driven test. Then, for each row in my data spreadsheet I pull in the request body for my test. At first I simply pulled the request from a data source value in my spreadsheet, but this became unmanageable in my spreadsheet.
So, another tactic. In my test data sheet (data source) I stored the file name that contains the payload I want to squirt in.
In the test itself, I put in a groovy step immediately before the the step I want to push the payload into.
The groovy script uses the data source to firstly get the file name containing the payload, I then read the contents of the file.
In the step I want to push the data into, I just use a get from data, e.g. {groovyStep#result}.
If this doesn’t completely make sense, let me know and I’ll update with screenshot when I have access to SoapUi.
Is there a way to export search results using suitescript 2.0 in the same way when exporting from the Search page using Export(CSV). Netsuite Answers says that this can be done by building a CSV file, I would like to know if I can run the Export(CSV) as is. I need to do this because I have many searches that I need to run weekly which have to be downloaded to Excel and I would like to have a script do this instead of manually selecting each one.
Use the N/task.SearchTask API.
The inbuilt solution provided by Netsuite is to schedule the saved search to send email with the saved search results to be send as attachment in CSV format .
Alternatively, you can also find third party library to convert JSON to CSV and convert the saved search result to JSON format you want to be in CSV
Really quick code of a scheduled script that puts the results of a saved search into an exiting file.
Ref: SuiteScript 2.0 API page 792
/**
*#NApiVersion 2.x
*#NScriptType ScheduledScript
*/
define(['N/task','N/log'],
function(task)
{
function execute(context)
{
//create search task
var myTask = task.create({
taskType: task.TaskType.SEARCH
});
myTask.savedSearchId = 4222;
myTask.fileId = 14581313;
var myTaskId = myTask.submit();
log.audit({title:"Task submitted.",
details:"Put results of savedSearchId:4222 in csv file InternalID:14581313"});
}
return {execute: execute
}
});
I then check if the file is new enough (the script didn't fail) and download and process it.
When I log a whole Purchase or sales order record object using JSON.stringifyy(SOobject);,the logger don't show the whole object, What could I do to see entire object. The log level used is Log.debug({})
As per NetSuite's documentation, you cannot log more than 3999 characters in one log - see excerpt from SuiteAnswers "log.debug(options)" page below:
For a temporary quick and easy solution to overcome this limitation in order to troubleshoot some specific part of your script, you can call email.send() and include the details in the email body.
Similar to what Krypton suggested, typically I will write my long JSON or other data directly to an output text log file in the file cabinet. This I find is more reliable because sandbox will not send out emails unless specifically configured to do so.
Our approach for long string is that we separate the long log string into several parts and print each one.
function logger(str) {
str.match(/.{1,3000}/g).forEach(function(smallString, idx) {
log.debug('part' + idx, smallString);
});
}
var longStr = 'xxxx.....xxxxxx'; // This is your long string
logger(longStr);
However, I think sending mail is a better way in this case :)
I have a performance analysis result which is saved in .trd file.
Is there any way to open this format? Or is it some kind of proprietary file which cannot be opened?
The .trd file is actually a SQLite database that can be opened with the likes of SQLiteSpy.
Inside, you will find various tables pertaining to the information captured during the test run.
Here is some example SQL for pulling out network statistics per HTTP request:
Total bytes received per request:
select requests.name,SUM(metrics.count) as "Count",SUM(metrics.total) as "bytes received" from requests
inner join metrics
on requests.id = metrics.request
where metrics.id = 3
group by requests.name
order by 1,2 desc
Total bytes sent per request:
select requests.name,SUM(metrics.count) as "Count",SUM(metrics.total) as "bytes sent" from requests
inner join metrics
on requests.id = metrics.request
where metrics.id = 4
group by requests.name
order by 1,2 desc
Note that the metric IDs in the above may change from 3 & 4 to other values.
Of relevance, there is a new version of Analyzer which was essentially a refresh of the entire component. This new version (v6.1 onwards) actually utilizes a PostgreSQL database.
I am marshalling a incoming message to XML(using JAXB) to ByteArrayOutputStream and sending to SFTP using out bound channel adapter.
outputChannel.send(new GenericMessage<ByteArrayOutputStream>(bos));
All works well, but the file name is named as "59262ea2-acda-e2be-770c-f4073390c191.msg"
I would like to save the file with a specific name based on the incoming message.
Incoming message is like : Message{name='myfilename'; field='abc'}
XML File : <MYMessage> <name>myfilename</name> <MYMessage>
I used remote-filename-generator-expression="payload.getName() + '.xml'" to save the file extension as "xml" works well too.
using "remote-filename-generator", I need to do extra work to construct the file name.
Just worndering can I set payload name before sending to channel ?
Thanks
It isn't clear how are you going to get file name from the ByteArrayOutputStream...
However the remote-filename-generator-expression can get access to the MessageHeaders.
So, if you will be able to specify the file name as header, there will be just enough to have this:
remote-filename-generator-expression="headers[fileName] + '.xml'"