Triggers: Difference between revisions

101 bytes removed ,  10 November 2016
m
no edit summary
mNo edit summary
mNo edit summary
Line 333: Line 333:
:<small>'''Trigger script:'''</small>
:<small>'''Trigger script:'''</small>
<source lang="javascript">
<source lang="javascript">
f = file("/sdcard/myfile.txt"); // Open the myfile.txt file on the SD card. If the file does not exist,
f = file("/sdcard/myfile.txt"); // Open myfile.txt on the SD card
                                 // it will be created.
                                 // If no file, it will be created
f.writeLine("one");            // Write the string "one" as a line to the file
f.writeLine("one");            // Write "one" as a line to the file
f.writeLine("two");
f.writeLine("two");
f.writeLine("three");
f.writeLine("three");
f.close();                      // Close the file, saving the data to the file. Until the file is closed,
f.close();                      // Close & save. Until closed,
                                 // the disk file is still empty.
                                 //     the file is still empty
var a = f.readLines();          // Read all lines of the file into the array a
var a = f.readLines();          // Read all lines of the file into the array a
</source>
</source>
Line 349: Line 349:
:<small>'''Trigger script:'''</small>
:<small>'''Trigger script:'''</small>
<source lang="javascript">
<source lang="javascript">
var xml = '<record id="' + entry().field("id") + '">' +  // Format XML record from the entry field values
var xml = '<record id="' + entry().field("id") + '">' +  // Format XML record
'<title>' + entry().field("title") + '</title>' +
'<title>' + entry().field("title") + '</title>' + // from entry field values
'<date>' + entry().field("date") + '</date>' +
'<date>' + entry().field("date") + '</date>' +
'</record>';
'</record>';
f = file("/sdcard/" + entry().field("title") + ".xml");  // Open file with same name as Entry Name
f = file("/sdcard/" + entry().field("title") + ".xml");  // File name is Entry Name
f.write(xml);                                            // Save XML data into the file
f.write(xml);                                            // Save XML data to the file
f.close();                                              // Close the file
f.close();                                              // Close the file
</source>
</source>