If anyone likes this concept of writing out an xml file of a selected entry from a table, I finally got this working basing it off the sample "Write an XML File.grid". To trigger the file write, I added a new task for the Table so it would trigger on the selection.
Here is the working code (not pretty or cleaned up but it does work and write out a file)...
==================
<param bottom="440" evenstyle="f:bg#1A1E22;" expand="true" left="470" oddstyle="f:bg#21252A;" oid="table" right="20" showlabel="false" style="size:Big;font:default;" top="190">
<config key="w.selectionparam">NameRow</config>
<config key="w.sortable">true</config>
<task tasktype="ogscript">var RowNum = params.getValue('table', 0);
var listname = params.getValue('cols.0', RowNum) + " " + params.getValue('cols.1', RowNum);
var listtitle = params.getValue('cols.2', RowNum)
//
params.setValue('fname10', 0, listname);
params.setValue('title10', 0, listtitle);
//
ogscript.debug('This is the variable value: ' + RowNum);
ogscript.debug('Selected Name is: ' + listname + '/' + listtitle);</task>
<task tasktype="ogscript">//Create a toplevel node, called "game"
var xmlDoc = ogscript.parseXML('<?xml version="1.0" encoding="UTF-8"?><PickedName/>');
var gameElement = xmlDoc.getDocumentElement();
var xmlfile = "SelectedName.xml"
var RowNum = params.getValue('table', 0);
var listname = params.getValue('cols.0', RowNum) + " " + params.getValue('cols.1', RowNum);
var listtitle = params.getValue('cols.2', RowNum)
//Create a home node with a short and long name attribute, with some text content.
var homeTeam = xmlDoc.createElement('SelName');
homeTeam.setTextContent(listname);
gameElement.appendChild(homeTeam);
//Create an away node with a short and long name attribute, with 10 player subelements.
var awayTeam = xmlDoc.createElement('SelTitle');
awayTeam.setTextContent(listtitle)
gameElement.appendChild(awayTeam);
// save the xml to file
var file = xmlfile;
ogscript.saveToFile(file, gameElement, true);
//Debug statements
ogscript.debug('This is the Selected Name: ' + listname);
ogscript.debug('This is the Selected Title: ' + listtitle);
ogscript.debug('This is the XML File Name: ' + file);</task>
</param>
==========================
....
------------------------------
JerryB
------------------------------
Original Message:
Sent: 07-09-2023 23:28
From: JerryB
Subject: Write a xml file based on the result of a list selection with mouse pointer
Down a rabbit hole again ....
I thought I might have been sending data too quickly, but that has turns out to be unlikely.
So now, I'm trying to write a simple xml file with only two tags when I click on a selection from a table. The functionality of the table is fine and does what I want it to but now I'd like to write that choice out to a xml file.
I'm basing my scripting off the "Write an XML File.grid" sample and the task is triggered by a button push in that sample. I'd like to trigger the task from the mouse click for selected table row. This is how my script looks (as it isn't working)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var RowNum = params.getValue('table', 0);
var listname = params.getValue('cols.0', RowNum) + " " + params.getValue('cols.1', RowNum);
var listtitle = params.getValue('cols.2', RowNum)
var savefile = "file2.xml"
//
params.setValue('fname10', 0, listname);
params.setValue('title10', 0, listtitle);
params.setValue('xmlfile', 0, savefile);
//
//
<task tasktype="ogscript">//Create a toplevel node, called "SelectedName"
var xmlDoc = ogscript.parseXML('<?xml version="1.0" encoding="UTF-8"?><SelectedName/>');
var ListSelection = xmlDoc.getDocumentElement();
var savefile = "file1.xml"
//Create a Name node and fill with the selected name
var selname = xmlDoc.createElement('Name');
selname.setTextContent('listname');
ListSelection.appendChild(selname);
//Create a Title node and fill with the select title
var seltitle = xmlDoc.createElement('Title');
seltitle.setTextContent('listtitle');
ListSelection.appendChild(seltitle);
// save the xml to file
//var file = params.getValue("savefile",0);
ogscript.saveToFile(savefile, ListSelection, true);
</task>
//
//
ogscript.debug('This is the variable value: ' + RowNum);
ogscript.debug('Selected Name is: ' + listname + '/' + listtitle);
ogscript.debug('Name to write to file is: ' + listname)
ogscript.debug('Title to write to file is: ' + listtitle)
ogscript.debug('XML File Name is: ' + savefile);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
So the question is: How do I trigger this 'file save' based on my selection from a table??
As I've said --- I'm a pretty good "monkey see - monkey do" but an absolutely terrible programmer/code /script writer.
Hope I've made this relatively clear....
Thanks for anyone's help on this!!
p.s. How do I determine a static path for the written file
------------------------------
JerryB
------------------------------