Alpha Video Training
Results 1 to 2 of 2

Thread: Syntax error on Javascript Function

  1. #1
    Member
    Real Name
    David Fricke
    Join Date
    Sep 2011
    Location
    Kenosha, WI
    Posts
    418

    Default Syntax error on Javascript Function

    I have a Xbasic function which looks up data from an SQL database and then passes it to a Javascript function.

    Xbasic
    Code:
    function getCustomerStatus as c (e as p)
    	
    'debug(1)
    
    dim cn AS SQL::Connection
    dim rs AS SQL::ResultSet
    dim args AS SQL::Arguments
    dim js as c
    dim sqlStmt as c
    dim flag as l
    dim custStatus as c
    dim customer_id as n
    
    
    
    'get the Customer ID
    customeridtemp = e.dataSubmitted.customeridtemp
    
    flag = cn.Open("::Name::SQL")
    if flag = .f. then
    	cn.close()
    	js = "alert('Error Connecting to Database);"
    	getCustomerStatus = js
    	exit function
    end if	
    
    
    'lookup from the database and get the customer info
    sqlStmt = "SELECT * FROM Customers WHERE customer_id = :custid"
    args.set("custid", customeridtemp)
    
    flag = cn.Execute(sqlStmt,args)
    if flag = .f. then
    	cn.close()
    	js = "alert('Error executing query');"
    	getCustomerStatus = js
    	exit function
    end if
    
    
    rs = cn.ResultSet
    custStatus = rs.ToJSONObjectSyntax()
    
    'pass back a call to a Javascript function... including the customer info data... now in JSON format.
    getCustomerStatus = "processCustomerStatus('" + custStatus + "');"
    
    
    cn.close()
    
    end function
    Javascript

    Code:
    function processCustomerStatus(custStatus) {
    
    	var custObj = JSON.parse(custStatus);
    	
    	var customer_id = custObj.customer_id;
    	var firstname = custObj.FirstName;
    	var lastname = custObj.LastName;
    	var city = custObj.City;
    	var state = custObj.State;
    	var zip = custObj.Zip;
    	var phone = custObj.PhoneNumber;
    	var email = custObj.Email;
    
    	{dialog.object}.setValue('FirstName',firstname);
    	{dialog.object}.setValue('LastName',lastname);
    	{dialog.object}.setValue('City',city);
    	{dialog.object}.setValue('State',state);
    	{dialog.object}.setValue('ZipCode',zip);
    	{dialog.object}.setValue('PhoneNumber',phone);
    	{dialog.object}.setValue('Email',email);
    	{dialog.object}.setValue('firstname_vb',firstname);
    	{dialog.object}.setValue('lastname_vb',lastname);
    	{dialog.object}.setValue('city_vb',city);
    	{dialog.object}.setValue('state_vb',state);
    	{dialog.object}.setValue('zipcode_vb',zip);
    	{dialog.object}.setValue('phoneNumber_vb',phone);
    	{dialog.object}.setValue('phoneNumber_vb_temp',phone);
    	{dialog.object}.setValue('email_vb',email);
    	{dialog.object}.panelSetActive('REVIEW_PANEL');
    
    }
    I get a Syntax Error when running in Working Preview. Live Preview generates no error and works. What am I missing here?

  2. #2
    Volunteer Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Lexington, KY
    Posts
    1,471

    Default Re: Syntax error on Javascript Function

    As a start, using the debug(1) command in the Xbasic script, get the value of custStatus and paste it into Notepad.
    Then put the javascript portion on a button, and using a debugger; put the value of custStatus into the javascript function and run the javascript in the Chrome debugger.
    This should get you closer to the answer.

    Jay
    Jay Talbott
    Lexington, KY


Similar Threads

  1. Javascript Syntax Help
    By mikeallenbrown in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 08-22-2014, 01:23 PM
  2. Syntax Error In Import Data from Excel Action Javascript
    By MRall in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 04-09-2013, 12:26 PM
  3. Action JavaScript not available in Grid Javascript function declarations
    By Clipper87 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 09-23-2010, 11:22 AM
  4. So confused with Javascript syntax - help!
    By Scholin in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 07-02-2010, 08:51 PM
  5. Javascript syntax help - again
    By Steve Workings in forum Application Server Version 10 - Web/Browser Applications
    Replies: 6
    Last Post: 03-31-2010, 08:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •