I am new with java-script, it might seems a stupid question, but I tried a lot to get the right result, but still fail... I have to read and write data in sqlite file, and I found this library which is described as a port by the developer, https://github.com/lovasoa/sql.js. Please see my code below:
First, I am selecting a local file via this HTML
<input type="file" id="check" onchange="working(this.files)">
The js file behind this is:
function working(data) {
//adding database
var sql = window.SQL;
var db = new sql.Database(data);
//writing a query
//read existing table called propertystring
var query = "SELECT * FROM propertystring";
var result = db.exec(query);
console.log(result);}
I am trying to debug using Google chrome console, its saying
Uncaught Error: no such table: propertystring
Although, I have entered in my sqlite database this table and its showing me in sqlitemen The description of table is as below:
-- Describe PROPERTYSTRING
CREATE TABLE "propertystring" (
"sValue" TEXT,
"TypeID" TEXT
)
INSERT INTO propertystring (sValue, TypeID) VALUES ("yes its working", "71")
I hope, its very simple thing and any person using sql.js can simple answer me.
Related
I am writing what should be a simple HTML form for users to make a reservation. However, having difficulty doing something I've done many times before - getting data from a GSheet and presenting it in an HTML form. Code snippets:
**Server side**
//Getting data from spreadsheet; expecting it to be an array of arrays.
function getMembers(){
const url = "https://my gsheet url"
const ss = SpreadsheetApp.openByUrl(url);
const ws = ss.getSheetByName("Members");
const row = ws.getLastRow()
const memberData = ws.getRange(2,1,row-1,7).getValues();
const array = JSON.stringify(memberData); //EDIT...helps get data to client side
return //array; //this data to be passed to browser when called. Type Error?
//Log(memberData) = //Looks like an array to me...
//[1,"Simmie","Smith","Simmie Smith","2020-01-01T05:00:00.000Z","temp","53120-1"],
//[2,"Fred","Williams","Fred Williams","2020-01-01T05:00:00.000Z","temp","53120-2"],
//[3,"Carleton","Johnson","Carleton Johnson","2020-01-01T05:00:00.000Z","temp","53120-3"],
//[4,"Caroll","Williams","Caroll Williams","2020-01-01T05:00:00.000Z","temp","53120-4"],
//[5,"Gabby","Williams","Gabby Williams","2020-01-01T05:00:00.000Z","temp","53120-5"]
//EDIT HtmlService code
function doGet(e){
return HtmlService.createTemplateFromFile('Reservations HTML')
.evaluate().setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
}
Calling the above server function when page loads so that member name can be presented in a select dropdown and other info from the array used elsewhere.
**Browser JS**
function getMemberData(){
google.script.run.withSuccessHandler(populateMembersDD).getMembers();
}
function populateMembersDD(data){
console.log(data) //undefined - same result FFox or Chrome..
memberInfo = data.filter(function(row){return true});
not getting any further than that because data is not passing to browser in a format with which I can apply necessary methods to get data into dropdown. Have tried various methods (slice, filter etc) to convert data into an array but none have worked. I suspect a type error, as though server function is not producing an object in array format. But I cannot figure out why. Have read many similar questions/answers on Stack but none have solved my problem. Help much appreciated as I am 24 hours in on solution experiments. Have many other apps where this basic code pattern works totally fine...
I'm working in a project and I'm facing a problem. I have some client stored in database, lets say one of them is Novák. Now I'm using jQuery (autocomplete), in order to get the clients in the client text field when I want to search. The problem is that, I'm geting Nov& #225;k instead of Novák. I have searched for an answer but could not find the correct one.
<script>
var availableWorkers = new Array();
#foreach(var w in selWorkers) {
var worker = w.fullName;
#:availableWorkers.push(#worker);
}
$(".workerTag").autocomplete({
source: availableWorkers
});
</script>
So, I think I have to add something here:
#:availableWorkers.push(#worker);
Thank you. All the best.
How to retrieve or display data on html page from db2 by sql adapter in ibm worklight?
What are the codes for these?
How to Display data in a text box?
How to Display data in a label?
How to Display data in a drop down box?
How to select check box?
like automatically getting data from db2 for example
Interests:Technology,Science,etc. Now the user can update/change
data and save.
How to select radio/option button? like
automatically getting data from db2 for example Gender:Male or
Female. Now the user can update/change data and save.
like in jsp.
Is the codes are same in android hybrid apps development or not?
<body>
<center><h2>Your Account Details</h2></center>
<%
String usertype="general";
String email=(String)session.getAttribute("email");
String pwd=(String)session.getAttribute("pwd");
String sex=new String();
Connection con=null;
try
{
if(email==null)
out.println("<center>Please Login to view your account!!!");
//MS ACCESS
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dsn1");
PreparedStatement pst=null;
pst=con.prepareStatement("select * from user1 where usertype=? and email=? and pwd=?");
//"select * from user1 where usertype='"+usertype+"' and email = '"+email+"' and pwd='"+pwd+"'"
synchronized(pst)
{
pst.setString(1, usertype);
pst.setString(2, email);
pst.setString(3, pwd);
}
ResultSet rs = pst.executeQuery();
while(rs.next())
{
//usertype=rs.getString(1);
email=rs.getString(2);
//pwd=rs.getString(3);
sex=rs.getString(4);
//out.println("<b>");
out.println ("<center><table>");
out.println("<tr>");
out.println("<td>");
out.println("<b>Email:</b> "+email);
out.println("</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>");
out.println("<b>Sex:</b> "+sex);
out.println("</td>");
out.println("</tr>");
}
catch(Exception e)
{
e.printStackTrace();
}
//return false;
finally
{
con.close();
}
%>
</body>
My suggestion:
Read the tutorials provided by IBM to learn about Worklight adapters and how they work
Search Stack Overflow, as this has been asked many times...
What you need to do is adapt the JavaScript snippets provided in the questions below to place the value, instead of inside a table or UL elements, to a textfield or a Select. It is the same principle repeating itself.
Because this is a duplicate, there is no value in copying code to this question as well.
Please review the following:
IBM Worklight - Unable to display data retrieved using SQL adapter
Invoking Worklight Adapter and Displaying that JSON data in list view as strings
use resultset returned by WL.Server.invokeSQLStatement within sql adapter procedure
Insertion of values in database
How to retrieve images from existing database using sql/http adapter from worklight application
Understand that placing data into HTML elements is unrelated to Worklight, rather it is a standard technique in JavaScript. You need to grasp the concept of that.
You can do that by finding the ID of the HTML element and appending data to it, or replacing it completely, or dynamically insert into it. This is demonstrated in the questions above.
<script language="javascript" >
function GetData(cell,row){
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("I:Work/database/72550.xls");
var excel_sheet = excel.Worksheets("CA 2012-2013 HMO Plans");
var data = excel_sheet.Cells(cell,row).Value;
document.getElementById('div1').innerText =data;
}
</script>
<input type="button" value="Hearing Services" onClick="GetData(45,2);" />
This is all in a table but I didn't think it was nec to display that, and of course file names are changed. All I need to know is how to pull from two cells at once from the same work sheet to display on a webpage. I got it working put only from one cell. How can I add another cell data to my result text?
is easier to take all the information inside a database, and do a cross join, as you usuing java, i recommend you use oracle, and so a simple cross join, depends on the head text of your excel sheets.
inside your code use odbc connection, you can simple get the connection part if you connect your database inside the sql developer.
I've got an update to my question.
What I really wanted to know was this:
How do I get csv data into netsuite?
Well, it seems I use the csv import tool to create a mapping and use this call to import the csv nlapiSubmitCSVImport(nlobjCSVImport).
Now my question is: How do I iterate through the object?!
That gets me half way - I get the csv data but I can't seem to find out how I iterate through it in order to manipulate the date. This is, of course, the whole point of a scheduled script.
This is really driving me mad.
#Robert H
I can think of a million reasons why you'd want to import data from a CSV. Billing, for instance. Various reports on data any company keeps and I wouldn't want to keep this in the file cabinet nor would I really want to keep the file at all. I just want the data. I want to manipulate it and I want to enter it.
Solution Steps:
To upload a CSV file we have to use a Suitelet script.
(Note: file - This field type is available only for Suitelets and will appear on the main tab of the Suitelet page. Setting the field type to file adds a file upload widget to the page.)
var fileField = form.addField('custpage_file', 'file', 'Select CSV File');
var id = nlapiSubmitFile(file);
Let's prepare to call a Restlet script and pass the file id to it.
var recordObj = new Object();
recordObj.fileId = fileId;
// Format input for Restlets for the JSON content type
var recordText = JSON.stringify(recordObj);//stringifying JSON
// Setting up the URL of the Restlet
var url = 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=108&deploy=1';
// Setting up the headers for passing the credentials
var headers = new Array();
headers['Content-Type'] = 'application/json';
headers['Authorization'] = 'NLAuth nlauth_email=amit.kumar2#mindfiresolutions.com, nlauth_signature=*password*, nlauth_account=TSTDRV****, nlauth_role=3';
(Note: nlapiCreateCSVImport: This API is only supported for bundle installation scripts, scheduled scripts, and RESTlets)
Let's call the Restlet using nlapiRequestURL:
// Calling Restlet
var output = nlapiRequestURL(url, recordText, headers, null, "POST");
Create a mapping using Import CSV records available at Setup > Import/Export > Import CSV records.
Inside the Restlet script Fetch the file id from the Restlet parameter. Use nlapiCreateCSVImport() API and set its mapping with mapping id created in step 3. Set the CSV file using the setPrimaryFile() function.
var primaryFile = nlapiLoadFile(datain.fileId);
var job = nlapiCreateCSVImport();
job.setMapping(mappingFileId); // Set the mapping
// Set File
job.setPrimaryFile(primaryFile.getValue()); // Fetches the content of the file and sets it.
Submit using nlapiSubmitCSVImport().
nlapiSubmitCSVImport(job); // We are done
There is another way we can get around this although neither preferable nor would I suggest. (As it consumes a lot of API's if you have a large number of records in your CSV file.)
Let's say that we don't want to use the nlapiCreateCSVImport API, so let's continue from the step 4.
Just fetch the file Id as we did earlier, load the file, and get its contents.
var fileContent = primaryFile.getValue();
Split the lines of the file, then subsequently split the words and store the values into separate arrays.
var splitLine = fileContent.split("\n"); // Splitting the file on the basis of lines.
for (var lines = 1,count=0; lines < splitLine.length; lines++)
{
var words = (splitLine[lines]).split(","); // words stores all the words on a line
for (var word = 0; word < words.length; word++)
{
nlapiLogExecution("DEBUG", "Words:",words[word]);
}
}
Note: Make sure you don't have an additional blank line in your CSV file.
Finally create the record and set field values from the array that we created above.
var myRec = nlapiCreateRecord('cashsale'); // Here you create the record of your choice
myRec.setFieldValue('entity', arrCustomerId[i]); // For example, arrCustomerId is an array of customer ID.
var submitRec = nlapiSubmitRecord(myRec); // and we are done
fellow NetSuite user here, I've been using SuiteScripts for a while now but never saw nlobjCSVImport object nor nlapiSubmitCSVImport .. I looked in the documentation, it shows, but there is no page describing the details, care to share where you got the doc from?
With the doc for the CSVImport object I might be able to provide some more help.
P.S. I tried posting this message as a comment but the "Add comment" link didn't show up for some reason. Still new to SOF
CSV to JSON:
convert csv file to json object datatable
https://code.google.com/p/jquery-csv/
If you know the structure of the CSV file, just do a for loop and map the fields to the corresponding nlapiSetValue.
Should be pretty straightforward.