I am fairly new to NetSuite scripting and have the following issue.
I am trying to send an email from SuiteScript 1.0. The Script is linked to the AFTER SUBMIT function of Sales Orders.
My code:
function OnAfterSubmit(record) {
var fromId = -5; //Authors' Internal ID
var sbj = 'subject';
var msg = '';
//load File from netSuite Document Repository with ID of 123
var orderid = nlapiGetRecordId();
var search = nlapiSearchRecord('salesorder', orderid);
var fileObj = nlapiLoadRecord(search.getRecordType(), search.getId());
//var detail = getOrderDetail(fileObj);
//Single Attachment - Attach File ID 123
//nlapiSendEmail(fromId, 'xyz#test1.example', sbj, msg, null, null, null, fileObj);
//multiple Attachments
//build Array of file objects
var attach = [fileObj];
//pass attach array as attachment parameter
nlapiSendEmail(fromId, 'charl#email.example', sbj, msg, null, null, null, attach);
}
I am trying to send the record that has been created by the user, via email.
The record parameter doesn't seem to be what I expect. The error I receive says "invalid search". When I used record.id, the error simply said "id". I also tried record.internalId.
function OnAfterSubmit(type) {
var fromId = -5; //Authors' Internal ID
var toEmail = 'charl#email.example';
var sbj = 'subject';
var msg = '';
var newRecord = nlapiGetNewRecord();
var recordAsJSON = JSON.stringify(newRecord);
var fileObj = nlapiCreateFile('salesorder.json', 'JSON', recordAsJSON);
nlapiSendEmail(fromId, toEmail, sbj, msg, null, null, null, fileObj);
}
Related
I'm writing a script that takes google sheet data and uploads my mailchimp subscriber data, where the edited cell values are sent over as updated merge tags. The original code came from here. I've got the script running successfully, accept for this one error:
"Invalid Resource","status":400,"detail":"Blank email address"
I understand the error according to the documentation in the mailchimp api documentation, but I'm not sure why it's not recognizing the subscriber data from the script:
var emHash = md5(em.toLowerCase()); //this is pulled from my md5 function
var payload = JSON.stringify({
"status_if_new": "subscribed",
"email_address": em,
"merge_fields": {
"LEAD": lead,
//rest of vars following same syntax
}
});
var options = {
"headers" : headers,
"payload": payload,
"method" : "put",
"muteHttpExceptions" : true
};
var response = UrlFetchApp.fetch('https://us15.api.mailchimp.com/3.0' + '/lists/' + 'xxxxxxx' + '/members/' + emHash,options);
Logger.log(response);
}
Last is the function triggered by editing so that changed values get sent over via the function above
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
var range = e.range;
var rowedited = range.getRowIndex();
if (activeSheet.getName() !== "ATTENDANCE"){
return;
Logger.log("Oops :(");
}
else {
var values = sheet.getRange(rowedited, 1, 1, 13).getValues()[0];
var em = values[2];
var lead = values[1];
//remaining vars omitted for brevity
sendToMailChimp_(em,lead...[etc.]);
}
Any thoughts?
I figured it out - I pulled an amateur move and had the columns attributed to the wrong array element.... So yes, I started at 1 and not 0
facepalm
It is now working!
send multiple parameter using ajax and save data into database....and in the case of packet i want value will remain unchange on form mean i don't want that my form reload so, how it is possible i'm a newbie please give your valuable suggestions
onsubmitbtn call on submit button
function onsubmitbtn(){
var packet = document.getElementById("packet").value;
var name = document.getElementById("name").value;
var number = document.getElementById("number").value;
var sub = document.getElementById("sub").value;
var zipcode = document.getElementById("zcode").value;
var city = document.getElementById("city").value;
var weight = document.getElementById("weight").value;
var data = "packet=" +packet+ "&name="+name+ "&number="+number+ "&sub="+sub+ "&zipcode="+zipcode+ "&city="+city+ "&weight="+weight;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
var response = request.responseText;
}
request.open("get", "PickUpInvertFormSubmit.jsp?"+data, true);
request.send();
}
i want to send multiple parameters in my ajax and save the value in my database. if the packet is more than one in that case i want that on submit but the value in input field will remain same
jsp code for insert data into database
String name = request.getParameter("name");
String[] splt = client.replaceAll("\\s+", "").split("\\|");
String number = request.getParameter("number");
String sub = request.getParameter("sub");
String zip = request.getParameter("zipcode");
int z = Integer.valueOf(zip);
String city = request.getParameter("city");
String pkt = request.getParameter("packet");
int p = Integer.valueOf(pcs);
String weight = request.getParameter("weight");
double w = Double.valueOf(weight);
Dbcon dbc = new Dbcon();
Connection con = dbc.ConnDb();
String query = "insert query"
+ "VALUES (?,?,?,?,?,?,?,CURRENT_DATE,CURRENT_DATE,CURRENT_TIMESTAMP)";
PreparedStatement psmt = null;
try {
psmt = con.prepareStatement(query);
psmt.setString(1, ....);
psmt.setString(2, .......);
psmt.setString(3, ........);
psmt.setInt(4, .......);
psmt.setString(5, .......);
psmt.setInt(6, ..........);
psmt.setDouble(7, .......);
psmt.executeUpdate();
} catch (Exception e) {
System.out.println(e);
e.printStackTrace();
} finally {
dbc.disconnect(null, null, null, psmt);
}
}
this code works perfectly when i use this code on action
onsubmit button event my form field get refreshed and no data save in database...
use this
function onsubmitbtn() {
var packet = document.getElementById("packet").value;
var name = document.getElementById("name").value;
var number = document.getElementById("number").value;
var sub = document.getElementById("sub").value;
var zipcode = document.getElementById("zcode").value;
var city = document.getElementById("city").value;
var weight = document.getElementById("weight").value;
$.ajax({
type: 'POST',
cache: false,
url: "PickUpInvertFormSubmit.jsp",
data: {
"packet": packet,
"name": name,
"number": number,
"sub": sub,
"zipcode": zipcode,
"city": city,
"weight": weight
},
success: function (data, textStatus, jqXHR) {
successMethod(data);
},
error: function (jqXHR, textStatus, errorThrown) {
errorMethod(errorThrown);
}
});
}
Your data can't be altered after submission and also can't be bookmarked.
you can also use alert("success: " + data); in success value of ajax function and same in error of the ajax method.
Using this, data is not appended to browser's URL and you don't have to modify your controller/jsp.
This method will make a call to URL in background and you can perform cleanup in the success method.
also import jQuery in head tag of your document as
<head>
<script type="text/javascript" src="jquery-3.2.1.js"></script>
</head>
You can download jQuery from here Download jQuery | jQuery
Hope this helps :)
All the variables are returning correct values but the the urlfetch response returns 403 or 401 (access denied).
First log output:
var payload = {
"apikey": API_KEY,
"filters": {
"sendtime_start": REPORT_START_DATE,
"sendtime_end": REPORT_END_DATE
}
};
Logger.log(payload );
Second log output:
var params = {
"method": "POST", //what MC specifies
"muteHttpExceptions": true,
"payload": payload,
"limit": 100
};
Logger.log(params);
Third log output:
var apiCall = function(endpoint) {
//issue with syntax here?
var apiResponse = UrlFetchApp.fetch(automationsList, params);
var json = JSON.parse(apiResponse);
Logger.log(apiResponse);
return json;
};
Automation API Call that is not working:
var automations = apiCall(automationsList);
var automationsData = automations.data;
for (var i = 0; i < automationsData.length; i++) {
// are these response parameters? are these specific values getting pulled from MC - these are the type of values i want?
var a = automationsData[i];
var aid = a.id; // identifies unique campaign *** does this have anything to do with the call function above - it used to be as cid b/c this was for campaigns before??
var emails_sent = a.emails_sent;
var recipients = a.recipients;
var report_summary = a.report_summary;
var settings = a.settings;
if (send_time) {
var r = apiCall(reports, cid); // why does this have cid? but the other one didn't??
var emails_sent = r.emails_sent;
var opens = r.opens;
var unique_opens = r.unique_opens;
var clicks = r.clicks;
var unique_clicks = r.unique_clicks;
var open_rate = (unique_opens / emails_sent).toFixed(4);
var click_rate = (unique_clicks / emails_sent).toFixed(4);
}
The for loop is not even gets executed because I get following error for automationsData:
TypeError: Cannot read property "data" from undefined. (line 82, file "Code")
The apiResponse there is somehow not working, any help is appreciated.
The problem is in how you set up your project in the Developers Console. Try to follow again the process here for you to verify if you already do it in the correct way.
You can also check the solution here in this SO question, he/she explained it here, why he/she get the same 401 and 403 error that you get.
As it turns out, I was using v3.0 for the Mailchimp api whereas I needed to use 2.0.
In simple, I am trying to retrieve the objectId for a particular user in parse (using Javascript). I can retrieve any other query in the database, such as username, phone, mailing address but not the objectId, here is how I retrieve the rest of the query:
var objectId = userInfo.get("objectId");
Any assistance would be greatly appreciated.
Below is more lines of the code (everything is retrieved beside objectId)
query.find({ success: function(array) {
// this means the query was a success, but we're not yet certain that we found anything
// the param to find's success is an array of PFObjects, possibly empty
if (array.length > 0) {
var userInfo = array[0];
var address = userInfo.get("address");
$scope.address = address;
var email = userInfo.get("username");
$scope.email = email;
var fullName = userInfo.get("fullName");
$scope.fullName= fullName;
var number = userInfo.get("phoneNumber");
$scope.number= number;
var objectId = userInfo.get("objectId");
$scope.objectId= objectId;
var mailingAddress = userInfo.get("mailingAddress");
$scope.mailingAddress = mailingAddress;
var plan = userInfo.get("plan");
$scope.plan = plan;
Thanks in advance
The js sdk provides an id member, so ...
$scope.objectId = userInfo.id;
As an aside, check out the JS guide on their site. It's a very well written doc. Pay particular attention to the code snippets in the objects and query sections.
var url = "http://api.reddit.com/";
var dataArray = [];
var working = function(){
var getData = JSON.parse(this.responseText);
var titles = getData.data.children;
for(var i=0, j=titles.length; i<j; i++)
{
var title = titles[i].data.title;
dataArray.push({
title: title,
favorite: 0
});
}
save(dataArray);
}; //working
var save = function(arg){
console.log(arg);
var db = Ti.Database.open("newData");
db.execute('CREATE TABLE IF NOT EXISTS redditTitles (id INTEGER PRIMARY KEY, name TEXT, favorite INTEGER)');
db.execute('INSERT INTO redditTitles (name, favorite) VALUES (?, ?)', arg.title, arg.favorite);
var rowID = db.lastInsertRowId;
//newRow.id = rowID;
//rows.close();
db.close();
gather();
};
var dataContent = [];
var gather = function(){
var db = Ti.Database.open("newData");
var dbRows = db.execute("SELECT name, favorite FROM redditTitles"); // Returns a Result Set object
while(dbRows.isValidRow()){
dataContent.push({
title: dbRows.fieldByName("name"),
fav: dbRows.fieldByName("favorite")
});
console.log("dataContent: "+ dataContent.title);
dbRows.next();
}
dbRows.close();
db.close();
console.log(dataContent);
userInterAPI();
};
var error = function(){
alert("Please check your network connection and try again.");
};
var client = Ti.Network.createHTTPClient({
onload: working,
onerror: error,
timeout: 5000
});
client.open("GET", url);
client.send();
So Basically me and my instructor have been scratching our heads trying to figure out why the arg will show all of the data but after the data is saved and we go to re console log it out, it will show up as null. Not sure why. Someone please help me!
You are saving just one item (Incorrectly - that's why is undefined). If you want to save everything you have to iterate through whole array.
var save = function(arg) {
console.log(arg);
var db = Ti.Database.open("newData");
db.execute('CREATE TABLE IF NOT EXISTS redditTitles (id INTEGER PRIMARY KEY, name TEXT, favorite INTEGER)');
db.execute("BEGIN"); // Transaction
arg.forEach(function(item) {
db.execute('INSERT INTO redditTitles (name, favorite) VALUES (?, ?)', item.title, item.favorite);
//var rowID = db.lastInsertRowId;
});
db.execute("COMMIT");
db.close();
gather();
};
In the function called gather - if you want to see selected title you should use:
console.log(dbRows.fieldByName("name"))
alternatively (This is what you wanted to use):
console.log(dataContent[dataContent.length - 1].title)
instead of
console.log(dataContent.title); // dataContent is an Array.
*Of course you better avoid using dataContent.length in every iteration. That's just an example.