Hide last authors
gru 15.1 1 {{figure image="export_persistence_en.png" clear="h1"}}
2 User interface for editing actions of type //Export (Persistence)//.
gru 1.3 3 {{/figure}}
gru 1.1 4
gru 15.1 5 Actions of type //export (persistence)// allow you to export the data of a form record, i.e. the data that has been submitted with the form. With a little bit of Javascript code, the exported data can be imported again later. This way it becomes possible to save form record data locally and restore it from a local backup. Filling form fields with data stored in an XML file is also possible via the actions of type [[//Import form values from XML//>>Formcycle.UserInterface.MyForms.WorkflowProcessing.Actions.ImportXML]].
gru 1.1 6
gru 15.1 7 == Options ==
gru 1.1 8
gru 15.1 9 ; Output file name
10 : The name for the export file.
gru 1.1 11
gru 15.1 12 ; Attach file to form record
13 : Determines whether the generated output file should be attached to the operation.
gru 1.1 14
gru 15.1 15 == Importing form data from a persistence file ==
gru 1.1 16
gru 15.1 17 When you open a form and the form contains a non-empty upload field named {{code language="none"}}fcp_persistence{{/code}}, or some other upload field contains a file whose file name without the extension is {{code language="none"}}fcp-persistence{{/code}}, form fields are pre-filled with the data form the persistence file.
gru 8.4 18
gru 15.1 19 The following example code makes it possible to realize this process with a button. The target of the form is set to its own URL when it is sent and all input fields except the upload field are deactivated. Subsequently, a submit of the form is executed which loads the contents of the file.
gru 8.4 20
21 {{code language="javascript"}}
gru 8.5 22 $('BUTTON[name="btnLoad"]').on('click', function(){
23 $('.xm-form').attr('action', window.location);
24 $('.xm-form input').not('[name=fcp_persistence]').attr('disabled', "disabled");
25 $('.xm-form textarea').attr('disabled', "disabled");
26 $('.xm-form select').attr('disabled', "disabled");
27 $('.xm-form').submit();
gru 8.4 28 });
29 $('[xn="fcp_persistence"] .img-uploaded-preview').visible(false);
30 {{/code}}
31
gru 15.1 32 Alternatively the following code can be used:
gru 13.6 33
gru 13.3 34 {{code language="javascript"}}
35 $('document').ready(function(){
36 var nameOfTriggerButton= "btnLoad";
gru 13.7 37
gru 13.3 38 var form = $("<form>", {
39 action:"?",
40 method:"post",
41 enctype:"multipart/form-data"
42 }).appendTo('body');
gru 13.7 43
gru 13.3 44 var upload = $("<input>", {
45 type:"file",
46 name:"fcp_persistence"
47 }).appendTo(form);
gru 13.7 48
gru 13.3 49 upload.change(function(){form.submit()});
50 $('BUTTON[name="'+nameOfTriggerButton+'"]').click(function(){upload.trigger('click')});
51 })
52 {{/code}}
53
sas 13.2 54 {{info}}
gru 15.1 55 [[You may also download an example form>>attach:Local import and export.zip]] illustrating this process and how to setup the workflow.
sas 13.2 56 {{/info}}
Copyright 2000-2024