Reputation: 43
I'm new to Suitescript and Netsuite automation in general. What I want to do is very basic. I want to schedule a saved search to execute every few hours and then post the resultant XML to an HTTP target. I have a bundle that does this for a connector but it doesn't let me see the contents so it's a bit of a black box. Does anyone have an example script I might adapt? I'd appreciate any configuration notes you might have as well. Thank you.
Upvotes: 2
Views: 1236
Reputation: 2250
Here is a very basic idea. I don't use XML, though, so this example is using JSON. This also assumes that you have a saved search you want to get the results from, and that there is only one row of data. If you have multiple rows, you would just declare a new array of data before the run().each() block, and push each new role of data into it at the end of that block.
define(['N/search','N/https'],function(search,https){
function execute(context){
search.load({
id:1234 // This should be your Saved Search ID
}).run().each(function(result){
var columns=result.columns;
var column0=result.getValue(columns[0]);
var column1=result.getValue(columns[0]);
var column2=result.getValue(columns[0]);
var column3=result.getValue(columns[0]);
return true;
});
var postData={
"column0":column0,
"column1":column1,
"column2":column2,
"column3":column3,
};
postData=JSON.stringify(postData);
var header=[];
header['Content-Type']='application/json';
header['Accept']='application/json';
var apiURL='https://whereverYouAreSendingThis.com';
try{
var response=https.post({
url:apiURL,
headers:header,
body:postData
});
var response=response.body;
}catch(er01){
log.error('ERROR',JSON.stringify(er01));
}
return true;
}
return {
execute: execute
};
});
That should get you started on the basic functionality of what you are trying to do.
Upvotes: 5