Thanks, Ray.
The exported file is a variable in the code. On this test record, the file name is "Rental Invoice_34970_171108_1948.txt". (I have attached the file). I have about ten different types of exports/imports that I want to do with this one routine.
Here is the code in the command button:
======================= "cmdCOPY TO NEW FORM" ON ELEMENT ENTRY CODE =========================
var vDest as String // Destination Order Type
var vRun as Int
var vPath as String = "C:\Sesame2\SesameExports\"
var vFileName as String = OrderType +"_" + OrderNumber + "_" + vDate + "_" + vTime + ".txt"
var vFullName as String = vPath + vFileName
var vExportSpec as String = "pgmExportFullOrderAndLines" //Use same Export Spec for all nine exports (177 fields)
var vImportSpec as String
If OrderType = "Rental Invoice" then {
vDest = "Rental Invoice"
vImportSpec = "pgmImportRentalInvoiceAndLines" // 177 fields
}
// Set 8 Global Variables to copy from Exported record to use in Imported record.
GlobalValue("gsImportSpec",vImportSpec) // Name of import spec to be used in Add Mode
GlobalValue("gsFullName",vFullName) // Name of exported file to be imported in Add Mode
// Six others here
vRun = @LoadExportSpec(vExportSpec)
If vRun = 1 Then {
RunExportSpec(vFullName,"|","",0,0,0,0,0,0,0,0) // NO Hdr, NO Pipe
// Set CopyForm Mode, Save Form, Go to Add Mode to import and update fields.
GlobalValue("gsCopyForm",1) // Set flag that CopyForm process is active.
FormCommit("")
vMenu = @SelectTreeItem("dudgeon!Forms!add data!ORDERS!ORDERS")
}
//============== END OF CODE ===============================
Here is the code On Form Entry that only runs in Add Mode if a flag is set from the export process:
//=============== ON FORM ENTRY CODE ===============
var vRun as Int // Validator state
var vImportSpec as String // Name of import spec to use
var vFullName as String // Name of file to import
// IMPORT COPIED RECORD HERE
IF @Mode() = 0 Then { // Only do in Add Mode
If @GlobalValue("gsCopyForm") = 1 Then { // Only do if CopyForm flag is set
FormCommit("") // Save this record before import
// Perform Import Process
vFullName = @GlobalValue("gsFullName")
If FileExists(vFullName) Then {
vImportSpec = @GlobalValue("gsImportSpec")
vRun = @LoadImportSpec(vImportSpec)
If vRun = 1 Then {
RunImportSpec(vImportSpec)
} Else { @Msg("Could not find the Export file named " + vFullName)
}
// End of Import Process
FormCommit("") // Save record with imports
GlobalValue("gsCopyForm",0)
// Clear 7 other GlobalValues here
// UPDATE OTHER FIELDS AS NEEDED USING SOME GLOBAL VARIABLES FROM EXPORTED RECORD
// UPDATE LINE ITEMS IN COPIED ORDER WITH NEW VALUES FROM THIS ORDER
} // END OF FILE EXISTS
} // END OF COPYFORM MODE
} // END OF ADD MODE
// ================== END OF CODE ======================
I have stripped out a lot of other code to just show the relevant parts. Hopefully I got all my {braces} correct.
The user is on a server-client connection, but the exports are temp only and go to local system. My testing is on a stand alone, not client-server. The export/import specs change depending on the type of source records. Exporting forms like orders with subform line items. After making a new record copy, I then modify key fields like Order Number, dates, contacts, etc. (I have excluded most of that code).