I'm working on a Dialog component that records sales. The Customer_ID is the primary key for the customer table and is a field in the dialog. I have defined an OnChange event for the Customer_ID that defines other fields based on the Customer_ID chosen as well as validating the ID. The user can type in the Customer_ID or select it through a grid component Lookup. The Customer_ID is a field in the top-level of the dialog. The stock items sold are listing in a repeating row container in the same dialog. The problem is that if Customer_ID is changed after some of the fields in the repeating section have been computed, the fields that involve client-side computations are zero or blank after the onChange event. I tried to solve the problem by adding {dialog.Object}.refreshClientSideComputations(); to the javascript returned by the AJAX callback, but it had no effect. The code I am using in the OnChange event AJAX callback is given below.
I had a similar instance where an OnChange event for the Store Location (also contained an AJAX callback with varToJSON to set field values) nulled the Customer_ID field after it fired. Finally, I added the Customer_ID value to the fields populated and the problem was solved but not explained.
Has anyone else experienced this? Does any know a solution? I'm going to try the _d method and see if it helps.
I had a similar instance where an OnChange event for the Store Location (also contained an AJAX callback with varToJSON to set field values) nulled the Customer_ID field after it fired. Finally, I added the Customer_ID value to the fields populated and the problem was solved but not explained.
Has anyone else experienced this? Does any know a solution? I'm going to try the _d method and see if it helps.
Code:
IF val(e.datasubmitted.Customer_ID) = 0 dim j as p j.Customer_Name = "CASH SALE" j.Customer_Address = "" j.Customer_CSZ = "" j.Customer_Phone = "" j.Reason = 0 j.CUSTBYLOCKEY = 0 j.Layaway_Total = 0 j.Layaway_Credit = 0 j.Account_Balance = 0 j.Account_Status = "" j.Crd_Cust = .f. dim jsTxt as c dim js as c jsTxt = varToJSON(j) js = "{dialog.object}.populate(" + jsTxt + "); {dialog.object}.prepare(); {dialog.Object}.refreshClientSideComputations();" serverside_5011c1459b6b4198adda7cb18865a498 = js ELSE dim cn as sql::connection dim flag as L 'open external database if cn.open("::Name::DiamExch") 'Specify that we are using Portable SQL syntax cn.PortableSQLEnabled = .t. 'Error handling if connection fails dim sqlCommand as c DIM args as sql::arguments args.add("LOCATION",convert_type(e.datasubmitted.location,"N")) args.add("CUSTOMER_ID",convert_type(e.datasubmitted.Customer_ID,"N")) dim cn as sql::connection sqlCommand = "SELECT * FROM JCUSTOM WHERE CUSTOMER_ID=:CUSTOMER_ID" if cn.execute(sqlCommand,args) if cn.resultSet.nextRow() ' yes there are records, do something dim rs as sql::resultset rs = cn.ResultSet dim j as p j.Customer_Name = alltrim(rs.data("firstname"))+" "+alltrim(rs.data("lastname")) if alltrim(rs.data("Street2"))>"" j.Customer_Address = alltrim(rs.data("Street1"))+"; "+alltrim(rs.data("Street2")) else j.Customer_Address = alltrim(rs.data("Street1")) end if if alltrim(rs.data("city"))="" .or. alltrim(rs.data("state"))="" j.Customer_CSZ = alltrim(rs.data("city"))+" "+alltrim(rs.data("state"))+" "+alltrim(rs.data("zip5"))+iif(rs.data("zip4")>"","-"+rs.data("zip4"),"") else j.Customer_CSZ = alltrim(rs.data("city"))+", "+alltrim(rs.data("state"))+" "+alltrim(rs.data("zip5"))+iif(rs.data("zip4")>"","-"+rs.data("zip4"),"") end if j.Customer_Phone = rs.data("telephone") j.Reason = rs.data("reason") ' Customer Found so Flag is true flag = .t. else 'invalid customer id set flag to false flag = .f. dim j as p j.Customer_ID = 0 j.Customer_Name = "CASH SALE" j.Customer_Address = "" j.Customer_CSZ = "" j.Customer_Phone = "" j.Reason = 0 j.CUSTBYLOCKEY = 0 j.Layaway_Total = 0 j.Layaway_Credit = 0 j.Account_Balance = 0 j.Account_Status = "" j.Crd_Cust = .f. dim jsTxt as c dim js as c jsTxt = varToJSON(j) js = "alert('Customer No. " + e.datasubmitted.Customer_ID + " is invalid. Please revise.');"+crlf() js = js+"{dialog.object}.populate(" + jsTxt + "); {dialog.object}.prepare(); {dialog.Object}.refreshClientSideComputations();" serverside_5011c1459b6b4198adda7cb18865a498 = js end if end if if flag 'Lookup CUSTBYLOC record if not found create one sqlCommand = "SELECT * FROM CUSTBYLOC WHERE CUSTOMER_ID=:CUSTOMER_ID AND LOCATION=:LOCATION" if cn.execute(sqlCommand,args) if cn.resultSet.nextRow() ' yes there are records, do something dim rs as sql::resultset rs = cn.ResultSet flag = .t. else 'Insert record dim sqlInsertStatement as c sqlInsertStatement = <<%txt% INSERT INTO CUSTBYLOC (LOCATION, CUSTOMER_ID) VALUES (:LOCATION, :CUSTOMER_ID) %txt% dim flag as l flag = cn.Execute(sqlInsertStatement,args) sqlCommand = "SELECT * FROM CUSTBYLOC WHERE CUSTOMER_ID= :CUSTOMER_ID AND LOCATION= :LOCATION" if cn.execute(sqlCommand,args) if cn.resultSet.nextRow() ' yes there are records, do something dim rs as sql::resultset rs = cn.ResultSet flag = .t. end if end if end if end if if flag j.CUSTBYLOCKEY = rs.data("CUSTBYLOCKEY") j.Layaway_Total = rs.data("LAYTOT") j.Layaway_Credit = rs.data("LAYCRD") j.Account_Balance = rs.data("BALANCE") j.Account_Status = rs.data("STATUS") j.Crd_Cust = rs.data("CRD_CUST") end if 'Now, close the connection cn.close() dim jsTxt as c jsTxt = varToJSON(j) js = "{dialog.object}.populate(" + jsTxt + "); {dialog.object}.prepare(); {dialog.Object}.refreshClientSideComputations();" serverside_5011c1459b6b4198adda7cb18865a498 = js end if end if END IF
Comment