I'm trying to create an action button in a grid to perform an append operation on the server that copies records from one table to another. The append operation works fine from within the operations section of the program, but when I try to execute it using a button I created from the Xbasic code, all I get is a red line on the web page, and no records are copied.
This is how I am creating the Action button by pasting the XB code from the append operation:
Screen Shot 09-25-18 at 12.59 AM.JPG
And this is the actual XB code. ("Crime_Reports" is the Master table, and "Crime_Reports_x" is the Transaction table.):
DIM Append as P
a_tbl = table.open("crime_reports")
append.t_db = "crime_reports_x"
ON ERROR GOTO ERROR25092018005558225
append.m_key = "P1_FIELD_1_CCN"
append.t_key = "Casenumber"
append.m_filter = ""
append.t_filter = ""
append.type = "Unique only"
append.m_count = 12
append.m_field1 = "P1_FIELD_1_CCN"
append.m_exp1 = "@CRIME_REPORTS_X->Casenumber"
append.m_field2 = "P1_FIELD_2_DATETIME"
append.m_exp2 = "@CRIME_REPORTS_X->Cfsdate"
append.m_field3 = "P1_FIELD_3_INCTITLE"
append.m_exp3 = "@CRIME_REPORTS_X->Incidenttype"
append.m_field4 = "P1_FIELD_4_ADDRESSFULL"
append.m_exp4 = "@CRIME_REPORTS_X->Location"
append.m_field5 = "P1_FIELD_5_BEATSECTOR"
append.m_exp5 = "@CRIME_REPORTS_X->Sectorname"
append.m_field6 = "P1_FIELD_6_SUMMARY"
append.m_exp6 = "@CRIME_REPORTS_X->Pgsummaryofinc"
append.m_field7 = "P1_FIELD_7_OFFICER"
append.m_exp7 = "@CRIME_REPORTS_X->Reportedby"
append.m_field8 = "CFSNUMBER"
append.m_exp8 = "@CRIME_REPORTS_X->Cfsnumber"
append.m_field9 = "OFFENSE"
append.m_exp9 = "@CRIME_REPORTS_X->Offense"
append.m_field10 = "XCOORD"
append.m_exp10 = "@CRIME_REPORTS_X->Xcoord"
append.m_field11 = "YCOORD"
append.m_exp11 = "@CRIME_REPORTS_X->Ycoord"
append.m_field12 = "CFSDATE"
append.m_exp12 = "@CRIME_REPORTS_X->Cfsdate"
append.t_count = 0
'Prompt for confirmation before running the Operation.......
dim rec_count as n
rec_count = a5_get_records_in_query("crime_reports_x",append.t_filter,-1,.f.)
message_text = "A maximum of "+rec_count + " record(s) will be appended from 'crime_reports_x', to 'crime_reports'. "+crlf(2)+ "OK to proceed?"
operation_result=ui_msg_box("Append Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
If operation_result <> ui_ok_selected then
end
end if
a_tbl.append()
GOTO CONTINUE25092018005558225
ERROR25092018005558225:
ON ERROR GOTO 0
ui_msg_box("Error","Error running Append Operation"+crlf()+error_text_get())
END
CONTINUE25092018005558225:
a_tbl.close()
'Display a dialog box showing the results of the Operation
dim args as sql::arguments
if eval_valid("arguments") then
if typeof(arguments) = "P" then
args = arguments
end if
end if
a5_append_op_result(a_records_processed,a_records_total,a_records_violated, "crime_reports","Append Operation Result",args)
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
This is what my grid looks like before I click on the new Action button to run the append operation:
Screen Shot 09-25-18 at 12.49 AM.JPG
And this is what I looks like after I click on the new Action button:
Screen Shot 09-25-18 at 12.51 AM.JPG
(Obviously I'm doing something wrong.)
Rich
This is how I am creating the Action button by pasting the XB code from the append operation:
Screen Shot 09-25-18 at 12.59 AM.JPG
And this is the actual XB code. ("Crime_Reports" is the Master table, and "Crime_Reports_x" is the Transaction table.):
DIM Append as P
a_tbl = table.open("crime_reports")
append.t_db = "crime_reports_x"
ON ERROR GOTO ERROR25092018005558225
append.m_key = "P1_FIELD_1_CCN"
append.t_key = "Casenumber"
append.m_filter = ""
append.t_filter = ""
append.type = "Unique only"
append.m_count = 12
append.m_field1 = "P1_FIELD_1_CCN"
append.m_exp1 = "@CRIME_REPORTS_X->Casenumber"
append.m_field2 = "P1_FIELD_2_DATETIME"
append.m_exp2 = "@CRIME_REPORTS_X->Cfsdate"
append.m_field3 = "P1_FIELD_3_INCTITLE"
append.m_exp3 = "@CRIME_REPORTS_X->Incidenttype"
append.m_field4 = "P1_FIELD_4_ADDRESSFULL"
append.m_exp4 = "@CRIME_REPORTS_X->Location"
append.m_field5 = "P1_FIELD_5_BEATSECTOR"
append.m_exp5 = "@CRIME_REPORTS_X->Sectorname"
append.m_field6 = "P1_FIELD_6_SUMMARY"
append.m_exp6 = "@CRIME_REPORTS_X->Pgsummaryofinc"
append.m_field7 = "P1_FIELD_7_OFFICER"
append.m_exp7 = "@CRIME_REPORTS_X->Reportedby"
append.m_field8 = "CFSNUMBER"
append.m_exp8 = "@CRIME_REPORTS_X->Cfsnumber"
append.m_field9 = "OFFENSE"
append.m_exp9 = "@CRIME_REPORTS_X->Offense"
append.m_field10 = "XCOORD"
append.m_exp10 = "@CRIME_REPORTS_X->Xcoord"
append.m_field11 = "YCOORD"
append.m_exp11 = "@CRIME_REPORTS_X->Ycoord"
append.m_field12 = "CFSDATE"
append.m_exp12 = "@CRIME_REPORTS_X->Cfsdate"
append.t_count = 0
'Prompt for confirmation before running the Operation.......
dim rec_count as n
rec_count = a5_get_records_in_query("crime_reports_x",append.t_filter,-1,.f.)
message_text = "A maximum of "+rec_count + " record(s) will be appended from 'crime_reports_x', to 'crime_reports'. "+crlf(2)+ "OK to proceed?"
operation_result=ui_msg_box("Append Operation",message_text,UI_OK_CANCEL+ UI_FIRST_BUTTON_DEFAULT+ UI_INFORMATION_SYMBOL)
If operation_result <> ui_ok_selected then
end
end if
a_tbl.append()
GOTO CONTINUE25092018005558225
ERROR25092018005558225:
ON ERROR GOTO 0
ui_msg_box("Error","Error running Append Operation"+crlf()+error_text_get())
END
CONTINUE25092018005558225:
a_tbl.close()
'Display a dialog box showing the results of the Operation
dim args as sql::arguments
if eval_valid("arguments") then
if typeof(arguments) = "P" then
args = arguments
end if
end if
a5_append_op_result(a_records_processed,a_records_total,a_records_violated, "crime_reports","Append Operation Result",args)
'If the Operation is run from within a Form or Browse, then refresh the window
if is_object(topparent.this) then
if topparent.Class() = "form" .or. topparent.class() = "browse" then
topparent.Refresh_layout()
end if
end if
This is what my grid looks like before I click on the new Action button to run the append operation:
Screen Shot 09-25-18 at 12.49 AM.JPG
And this is what I looks like after I click on the new Action button:
Screen Shot 09-25-18 at 12.51 AM.JPG
(Obviously I'm doing something wrong.)
Rich