XML to generate Home and Away tables

I have been using the xml example grid from the Dashboard U Panel Builder 107 video as a starting point for my project.

I will be receiving an rss feed link which I would like to enter into a text field then from that it would like generate two separate tables for home and away team lists from the link.

One other thing is to add an additional column in the table which adds First Name + last name together

I have attached an example of the xml from the rss feed.

Apologies in advance and any help is greatly appreciated. Thanks

League.xml var filepath = params.getValue(8,params.getValue(9,0)); ogscript.debug (filepath); var XMLDoc = ogscript.parseXML(filepath); if (XMLDoc == null) { ogscript.debug('Failed to read team data file'); } else { // clear out the existing squad data for (var i = 0; i < params.getValue(0xa, 0); ++i) { params.setValue(2, i, "blank"); params.setValue(3, i, 0); params.setValue(5, i, "blank"); params.setValue(6, i, "blank"); } ogscript.debug('Parsing XML'); var found=XMLDoc.getElementsByTagName('player'); ogscript.debug('search found ' + found.length + ' items'); params.setValue(0xa, 0, found.length); for (var i = 0; i < found.length; i++) { var node = found.item(i); var shirt = node.getAttribute('shirtNumber'); var firstName = node.getAttribute('firstName'); var position = node.getAttribute('position'); var lastName = node.getAttribute('lastName'); ogscript.debug(i + ": " + shirt + ", " + firstName + ", " + position + ", " + lastName); params.setValue(3, i, Number(shirt)); params.setValue(2, i, firstName); params.setValue(5, i, lastName); params.setValue(6, i, position); } }
var filepath = ogscript.getPrivateString('constants','filepath'); var XMLDoc; ogscript.debug('Reading XML file: ' + filepath); XMLDoc = ogscript.parseXML(filepath); if (XMLDoc == null) { ogscript.debug('Failed to read file'); } else { ogscript.debug('Parsing XML'); var found = ogscript.runXPath('/league/team', XMLDoc); ogscript.debug('search found ' + found.length + ' items'); params.setValue(0xb, 0, found.length); // teams = length for (var i = 0; i < found.length; i++) { var node = found.item(i); var teamname = node.getAttribute('name'); var filename = node.getAttribute('filename'); ogscript.debug(i + ": " + filename); params.setValue(8, i, filename); // teamFilePaths[i] = filename } params.setValue(0x9, 0, 0); // league = 0 (triggers on change)

}


var squadSize = params.getValue(0xa, 0);
var teams = params.getValue(0xb, 0);

for (var i = 0; i < squadSize; i++)
{
params.setValue(0x2, i, “blank”);
params.setValue(0x3, i, 0);
params.setValue(0x5, i, “blank”);
params.setValue(0x6, i, “blank”);
}
for (var i = 0; i < teams; ++i)
{
params.setValue(0x7, i, “blank”);
params.setValue(0x8, i, “blank”);
}
params.setValue(0xa, 0, 0);
params.setValue(0xb, 0, 0);
ogscript.rename(‘squadLabel’, ‘blank’);







Hi Sam,

I spent some time making a custom panel which reads the XML file you provided. I had to make a number of assumptions on statistics and layout so hopefully this will get you on the right track. There are a few things worth mentioning to help you understand the design of the panel.

I used “a” and “h” as a naming convention prefix for the away/home parameters. I also used “ap” and “hp” as a prefix for away/home player parameters.

The home and away player tables are represented by parameters “ap_table” and “hp_table”

You can change the columns that will appear in the table by editing the constraints for the player tables mentioned above

You can change the table column names by changing the “name” field on the parameter (I changed this for the Full Name column)

Below is the source of the panel. Please have a look and let me know if you have any questions.

ap_full_name ap_first_name ap_last_name ap_match_name ap_position ap_shirt_num ap_formation hp_full_name hp_first_name hp_last_name hp_match_name hp_position hp_shirt_num hp_formation function getPlayerInfo(XMLDoc, contestant_id, team){ //Extracts player info from source var players_path = '/matchStats/liveData/lineUp[@contestantId="'+contestant_id+'"]/player' var players = ogscript.runXPath(players_path, XMLDoc); for (var i = 0; i < players.length; i++) { var node = players.item(i); var playerId = node.getAttribute('playerId'); var formationPlace = node.getAttribute('formationPlace'); var positionSide = node.getAttribute('positionSide'); var shirtNumber = node.getAttribute('shirtNumber'); var matchName = node.getAttribute('matchName'); var lastName = node.getAttribute('lastName'); var firstName = node.getAttribute('firstName'); var position = node.getAttribute('position');
  if (team=="away"){
  params.setValue("ap_id", i, playerId);
  params.setValue("ap_formation", i, formationPlace);
  params.setValue("ap_position", i, positionSide);
  params.setValue("ap_shirt_num", i, shirtNumber);
  params.setValue("ap_match_name", i, matchName);
  params.setValue("ap_last_name", i, lastName);
  params.setValue("ap_first_name", i, firstName);
  params.setValue("ap_shirt_num", i, position);
  params.setValue("ap_full_name", i, firstName+" "+lastName);
  }
  else if (team=="home"){
  params.setValue("hp_id", i, playerId);
  params.setValue("hp_formation", i, formationPlace);
  params.setValue("hp_position", i, positionSide);
  params.setValue("hp_shirt_num", i, shirtNumber);
  params.setValue("hp_match_name", i, matchName);
  params.setValue("hp_last_name", i, lastName);
  params.setValue("hp_first_name", i, firstName);
  params.setValue("hp_shirt_num", i, position);
  params.setValue("hp_full_name", i, firstName+" "+lastName);
     }

}
}

function getTeamInfo(XMLDoc){
//Extracts team info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/contestants/contestant’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);
var id = node.getAttribute(‘id’);
var position = node.getAttribute(‘position’);
var code = node.getAttribute(‘code’);
var officialName = node.getAttribute(‘officialName’);
var shortName = node.getAttribute(‘shortName’);

  if (position=="away"){
     params.setValue("a_id", 0, id);
     params.setValue("a_name", 0, name);
     params.setValue("a_code", 0, code);
     params.setValue("a_official_name", 0, officialName);
     params.setValue("a_short_name", 0, shortName);
     
     }
  else if (position=="home"){
     params.setValue("h_id", 0, id);
     params.setValue("h_name", 0, name);
     params.setValue("h_code", 0, code);
     params.setValue("h_official_name", 0, officialName);
     params.setValue("h_short_name", 0, shortName);
     }

}
}

var XMLDoc = ogscript.parseXML(params.getValue(“rss_feed”, 0));
if (XMLDoc == null) {
ogscript.debug(‘Failed to find source’);
} else {
ogscript.debug(“Found source”);

//Grabbing Team Info
getTeamInfo(XMLDoc);

//Grabbing Player Info
getPlayerInfo(XMLDoc, params.getValue(“h_id”, 0), “home”);
getPlayerInfo(XMLDoc, params.getValue(“a_id”, 0 ), “away”);

}


//Emptying team stats
//Away stats
params.setValue(“a_id”, 0, null);
params.setValue(“a_code”, 0, null);
params.setValue(“a_name”, 0, null);
params.setValue(“a_official_name”, 0, null);
params.setValue(“a_short_name”, 0, null);
//Home stats
params.setValue(“h_id”, 0, null);
params.setValue(“h_code”, 0, null);
params.setValue(“h_name”, 0, null);
params.setValue(“h_official_name”, 0, null);
params.setValue(“h_short_name”, 0, null);

//Emptying player stats
var empty = new Array();
//Away stats
params.setAllValues(“ap_id”, empty);
params.setAllValues(“ap_first_name”, empty);
params.setAllValues(“ap_formation”, empty);
params.setAllValues(“ap_last_name”, empty);
params.setAllValues(“ap_match_name”, empty);
params.setAllValues(“ap_position”, empty);
params.setAllValues(“ap_shirt_num”, empty);
params.setAllValues(“ap_full_name”, empty);
//Home stats
params.setAllValues(“hp_id”, empty);
params.setAllValues(“hp_first_name”, empty);
params.setAllValues(“hp_formation”, empty);
params.setAllValues(“hp_last_name”, empty);
params.setAllValues(“hp_match_name”, empty);
params.setAllValues(“hp_position”, empty);
params.setAllValues(“hp_shirt_num”, empty);
params.setAllValues(“hp_full_name”, empty);

​

Hi David, thanks for taking the time to look over this.

What you have done is amazing and I appreciate the help.

One last thing, using what you have done as I starting point I made an attempt to fetch the match officials data I just can’t seem to get it working.

Can you tell me where I am going wrong. Thanks

ap_full_name ap_first_name ap_last_name ap_match_name ap_position ap_shirt_num ap_formation hp_full_name hp_first_name hp_last_name hp_match_name hp_position hp_shirt_num hp_formation mo_full_name mo_first_name mo_last_name mo_type mo_id function getPlayerInfo(XMLDoc, contestant_id, team){ //Extracts player info from source var players_path = '/matchStats/liveData/lineUp[@contestantId="'+contestant_id+'"]/player' var players = ogscript.runXPath(players_path, XMLDoc); for (var i = 0; i < players.length; i++) { var node = players.item(i); var playerId = node.getAttribute('playerId'); var formationPlace = node.getAttribute('formationPlace'); var positionSide = node.getAttribute('positionSide'); var shirtNumber = node.getAttribute('shirtNumber'); var matchName = node.getAttribute('matchName'); var lastName = node.getAttribute('lastName'); var firstName = node.getAttribute('firstName'); var position = node.getAttribute('position');
  if (team=="away"){
  params.setValue("ap_id", i, playerId);
  params.setValue("ap_formation", i, formationPlace);
  params.setValue("ap_position", i, positionSide);
  params.setValue("ap_shirt_num", i, shirtNumber);
  params.setValue("ap_match_name", i, matchName);
  params.setValue("ap_last_name", i, lastName);
  params.setValue("ap_first_name", i, firstName);
  params.setValue("ap_shirt_num", i, position);
  params.setValue("ap_full_name", i, firstName+" "+lastName);
  }
  else if (team=="home"){
  params.setValue("hp_id", i, playerId);
  params.setValue("hp_formation", i, formationPlace);
  params.setValue("hp_position", i, positionSide);
  params.setValue("hp_shirt_num", i, shirtNumber);
  params.setValue("hp_match_name", i, matchName);
  params.setValue("hp_last_name", i, lastName);
  params.setValue("hp_first_name", i, firstName);
  params.setValue("hp_shirt_num", i, position);
  params.setValue("hp_full_name", i, firstName+" "+lastName);
     }

}
}

function getTeamInfo(XMLDoc){
//Extracts team info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/contestants/contestant’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);
var id = node.getAttribute(‘id’);
var position = node.getAttribute(‘position’);
var code = node.getAttribute(‘code’);
var officialName = node.getAttribute(‘officialName’);
var shortName = node.getAttribute(‘shortName’);

  if (position=="away"){
     params.setValue("a_id", 0, id);
     params.setValue("a_name", 0, name);
     params.setValue("a_code", 0, code);
     params.setValue("a_official_name", 0, officialName);
     params.setValue("a_short_name", 0, shortName);
     
     }
  else if (position=="home"){
     params.setValue("h_id", 0, id);
     params.setValue("h_name", 0, name);
     params.setValue("h_code", 0, code);
     params.setValue("h_official_name", 0, officialName);
     params.setValue("h_short_name", 0, shortName);
     }

}
}

function getMatchOfficialInfo(XMLDoc){
//Extracts match official info from source
var found = ogscript.runXPath(‘/matchStats/liveData/matchDetailsExtra/matchOfficials/matchOfficial’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var id = node.getAttribute(‘id’);
var firstName = node.getAttribute(‘firstName’);
var lastName = node.getAttribute(‘lastName’);
var type = node.getAttribute(‘type’);

  params.setValue("mo_id", i, id);
  params.setValue("mo_first_name", i, firstName);
  params.setValue("mo_last_name", i, lastName);
  params.setValue("mo_type", i, type);
  params.setValue("mo_full_name", i, firstName+" "+lastName);

}
}

var XMLDoc = ogscript.parseXML(params.getValue(“rss_feed”, 0));
if (XMLDoc == null) {
ogscript.debug(‘Failed to find source’);
} else {
ogscript.debug(“Found source”);

//Grabbing Team Info
getTeamInfo(XMLDoc);

//Grabbing Player Info
getPlayerInfo(XMLDoc, params.getValue(“h_id”, 0), “home”);
getPlayerInfo(XMLDoc, params.getValue(“a_id”, 0 ), “away”);

//Grabbing Team Info
getTeamInfo(XMLDoc);

}


//Emptying team stats
//Away stats
params.setValue(“a_id”, 0, null);
params.setValue(“a_code”, 0, null);
params.setValue(“a_name”, 0, null);
params.setValue(“a_official_name”, 0, null);
params.setValue(“a_short_name”, 0, null);
//Home stats
params.setValue(“h_id”, 0, null);
params.setValue(“h_code”, 0, null);
params.setValue(“h_name”, 0, null);
params.setValue(“h_official_name”, 0, null);
params.setValue(“h_short_name”, 0, null);

//Emptying player stats
var empty = new Array();
//Away stats
params.setAllValues(“ap_id”, empty);
params.setAllValues(“ap_first_name”, empty);
params.setAllValues(“ap_formation”, empty);
params.setAllValues(“ap_last_name”, empty);
params.setAllValues(“ap_match_name”, empty);
params.setAllValues(“ap_position”, empty);
params.setAllValues(“ap_shirt_num”, empty);
params.setAllValues(“ap_full_name”, empty);
//Home stats
params.setAllValues(“hp_id”, empty);
params.setAllValues(“hp_first_name”, empty);
params.setAllValues(“hp_formation”, empty);
params.setAllValues(“hp_last_name”, empty);
params.setAllValues(“hp_match_name”, empty);
params.setAllValues(“hp_position”, empty);
params.setAllValues(“hp_shirt_num”, empty);
params.setAllValues(“hp_full_name”, empty);

//Emptying official stats
var empty = new Array();
//Official stats
params.setAllValues(“mo_id”, empty);
params.setAllValues(“mo_type”, empty);
params.setAllValues(“mo_first_name”, empty);
params.setAllValues(“mo_last_name”, empty);
params.setAllValues(“mo_full_name”, empty);

​

Hi Sam,

All of your new code for the match officials works perfectly fine. The only problem is that you aren’t triggering the new function.

You can see the same getTeamInfo(XMLDoc) function is triggered twice. You just need to change the second one to getMatchOfficialInfo(XMLDoc).

//Grabbing Team Info
getTeamInfo(XMLDoc);

//Grabbing Player Info
getPlayerInfo(XMLDoc, params.getValue(“h_id”, 0), “home”);
getPlayerInfo(XMLDoc, params.getValue(“a_id”, 0 ), “away”);

//Grabbing Team Info
getTeamInfo(XMLDoc);​
I also noticed you are saving the match official first and last name to mo_full_name but this parameter doesn’t exist. You already have it defined in your mo_table so all you need to do is add the mo_full_name parameter just like all the other table entries. Keep in mind you can change the “name” value of the parameters to change the column name if you like.

Please let me know if you have any questions.

In case you’re curious, I was able to determine the issue by using the ogscript.debug() function. This function can print statements to the openGear Debug Information console. You can open this console by selecting Views > openGear Debug Information from DashBoard. It really is a great tool for troubleshooting issues.

I added a ogscript.debug(“some text”) line to to the top of your match official code and noticed it was not being printed. This told me your code was not being executed at all and narrowed down where the problem was. It makes sense that the line was not printed because code inside functions is only run when the function is called.

Hi Dave,

This is now working perfectly now and I’ve been able to retrieve data for team managers as well.

I am primarily a motion graphics designer with not much experience with dashboard, so this is a great start for me to build on.

Thanks again for taking the time to help out.

All the best,
Sam

Hi Dave,

I had a go trying to pull team stats. I know I’m doing something wrong but don’t know where to start.

Any help is appreciated. Thanks

Maxime Jake Andy Ranko Javain Russell Janio Leonard Cristián Andrés Brian Deiber Jair Michael Bruno Miguel Ryan Kamron Thomas Florian Patrick Ryan Tosaint 1 3 6 5 2 8 4 7 11 9 10 6nmcuw8asxh6k3l5khx5atmfp 5hxlj4ash5nuwnt40mf5af46h 5r72qv2gbsyevp837ztsye28l 3mdm2bd45bybp9zbt6aspgq21 2fyga1shd4mwcn90mze2pe4tl cibach2kp6y1w697co2e4k2c5 vw73lu7w6gr72789vp49zmc5 bhkecr2u6neb933eo468i82ui 3oj41up7cc77o5qj3i65szemt f5i3q488txatpqe9tvmc0838q dp3chasr11o48ehnokswl8l7u 2jwbnsl7zicnbgutmpop29d61 3f2otwd2ozwk89319ssh9yjmd emzg4nwcze4zv4f4sh9t7bdn9 4oz12ku4mdjsq7y4sgogpwg2y 84gabnykc01v70413vehqyvah 69chuz7we7jlx255o0ym0m0np bww0h67l7g6o9syrkp12s7pih bialn02i06gihzao8dsjvmc8a 68oxh92004pbiboo5b5bf4pg5 Crépeau Nerwinski Rose Veselinović Brown Teibert Bikel Figueiredo Silva Owusu Dájome Arboleda White Caicedo Mideros Baldisimo Boialvo Gaspar Gauld Habibullah Hasal Jungwirth Metcalfe Raposo Ricketts M. Crépeau J. Nerwinski A. Rose R. Veselinović J. Brown R. Teibert Janio Bikel L. Owusu C. Dájome B. White D. Caicedo M. Baldisimo Bruno Gaspar R. Gauld K. Habibullah T. Hasal F. Jungwirth P. Metcalfe R. Raposo T. Ricketts Centre Left Left/Centre Centre/Right Right Left/Centre Centre Centre/Right Left/Centre Centre Centre/Right Goalkeeper Defender Defender Defender Defender Midfielder Midfielder Midfielder Striker Striker Striker Substitute Substitute Substitute Substitute Substitute Substitute Substitute Substitute Substitute Brad Nick Matt Jhohan Sebastián Hector Osvaldo Alexander Daniel Tomás Cecilio Andrés Diego Santiago Sebastián Sebastian Julio César Jon Frederik Žan Jared Rodney Iván Aedan Andrew 1 3 6 5 2 4 8 11 10 7 9 5ym1q9duaf8gaumjc83ze4vyt 8mjjt1miy57nwm5iy8usck4q1 3zvj76iwkxqp853t8sjt58t1 2v9a6ag22zeaezp0t32mo6i21 crlprp30citeo87zkm7juxlg5 5j2hy92q8f17nppznxrp8kxxx cz3k865qdwn8apn8e6xa2lu6s 81hv42gi3qhbs00zoro50y1nt cfth80ffvgnveork3pqd14atx ca82vaxv1vz6x0dye3gafzjkl bovgpaqiyr161smsebisx3o5 54b4j04ondrq28e4eenma1rai 4d6cfs28p6vb6q1ijkw3dks7p ecp53k8d0t7yczah3aebn0yne b7hyxpaqt3ymfbuah1yop5rai ev5e7r7m60jqpvaxigduuwa1 23pxtcocf0xyxeh31ac3hxgx5 dp79admqqqmme9e6l9bhu41gq 637c2iedo7modc3ekt36c2m7d 1e8v2xaqa6v181ryoqids2zmx Stuver Lima Besler Romaña Espitia Jimenez Ring Pereira Gil Pochettino Domínguez Ruiz Fagúndez Pepe Driussi Berhalter Cascante Solórzano Gallagher Kleemann Kolmanič Presson Stroud Redes Cáceres Stanley Tarbell B. Stuver N. Lima M. Besler J. Romaña H. Jimenez A. Ring Daniel Pereira T. Pochettino C. Domínguez D. Fagúndez S. Driussi S. Berhalter J. Cascante J. Gallagher F. Kleemann Ž. Kolmanič Jared Stroud R. Redes A. Stanley A. Tarbell Centre Left Left/Centre Centre/Right Right Left/Centre Centre/Right Left Centre Right Centre Goalkeeper Defender Defender Defender Defender Defensive Midfielder Defensive Midfielder Attacking Midfielder Attacking Midfielder Attacking Midfielder Striker Substitute Substitute Substitute Substitute Substitute Substitute Substitute Substitute Substitute ap_full_name ap_first_name ap_last_name ap_match_name ap_position ap_shirt_num ap_formation hp_full_name hp_first_name hp_last_name hp_match_name hp_position hp_shirt_num hp_formation Maxime Crépeau Jake Nerwinski Andy Rose Ranko Veselinović Javain Brown Russell Teibert Janio Bikel Figueiredo Silva Leonard Owusu Cristián Andrés Dájome Arboleda Brian White Deiber Jair Caicedo Mideros Michael Baldisimo Bruno Miguel Boialvo Gaspar Ryan Gauld Kamron Habibullah Thomas Hasal Florian Jungwirth Patrick Metcalfe Ryan Raposo Tosaint Ricketts Brad Stuver Nick Lima Matt Besler Jhohan Sebastián Romaña Espitia Hector Osvaldo Jimenez Alexander Ring Daniel Pereira Gil Tomás Pochettino Cecilio Andrés Domínguez Ruiz Diego Santiago Fagúndez Pepe Sebastián Driussi Sebastian Berhalter Julio César Cascante Solórzano Jon Gallagher Frederik Kleemann Žan Kolmanič Jared Presson Stroud Rodney Iván Redes Cáceres Aedan Stanley Andrew Tarbell duy1fgi7q8wkysvm6v6kejld5 di08wknq61nq7rt4oct7i8ted 1ig2npfzwpgm8yro3o104a9xx 4irk92ip7udts4b79eh4v602d Mendoza Garner McKay Penso Rosendo Adam Ian Tori Main Lineman 1 Lineman 2 Fourth official mo_full_name mo_first_name mo_last_name mo_type mo_id function getPlayerInfo(XMLDoc, contestant_id, team){ //Extracts player info from source var players_path = '/matchStats/liveData/lineUp[@contestantId="'+contestant_id+'"]/player' var players = ogscript.runXPath(players_path, XMLDoc); for (var i = 0; i < players.length; i++) { var node = players.item(i); var playerId = node.getAttribute('playerId'); var formationPlace = node.getAttribute('formationPlace'); var positionSide = node.getAttribute('positionSide'); var shirtNumber = node.getAttribute('shirtNumber'); var matchName = node.getAttribute('matchName'); var lastName = node.getAttribute('lastName'); var firstName = node.getAttribute('firstName'); var position = node.getAttribute('position');
  if (team=="away"){
  params.setValue("ap_id", i, playerId);
  params.setValue("ap_formation", i, formationPlace);
  params.setValue("ap_position_side", i, positionSide);
  params.setValue("ap_shirt_num", i, shirtNumber);
  params.setValue("ap_match_name", i, matchName);
  params.setValue("ap_last_name", i, lastName);
  params.setValue("ap_first_name", i, firstName);
  params.setValue("ap_position", i, position);
  params.setValue("ap_full_name", i, firstName+" "+lastName);
  }
  else if (team=="home"){
  params.setValue("hp_id", i, playerId);
  params.setValue("hp_formation", i, formationPlace);
  params.setValue("hp_position_side", i, positionSide);
  params.setValue("hp_shirt_num", i, shirtNumber);
  params.setValue("hp_match_name", i, matchName);
  params.setValue("hp_last_name", i, lastName);
  params.setValue("hp_first_name", i, firstName);
  params.setValue("hp_position", i, position);
  params.setValue("hp_full_name", i, firstName+" "+lastName);
     }

}
}

function getTeamInfo(XMLDoc){
//Extracts team info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/contestants/contestant’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);
var id = node.getAttribute(‘id’);
var position = node.getAttribute(‘position’);
var code = node.getAttribute(‘code’);
var officialName = node.getAttribute(‘officialName’);
var shortName = node.getAttribute(‘shortName’);

  if (position=="away"){
     params.setValue("a_id", 0, id);
     params.setValue("a_name", 0, name);
     params.setValue("a_code", 0, code);
     params.setValue("a_official_name", 0, officialName);
     params.setValue("a_short_name", 0, shortName);
     
     }
  else if (position=="home"){
     params.setValue("h_id", 0, id);
     params.setValue("h_name", 0, name);
     params.setValue("h_code", 0, code);
     params.setValue("h_official_name", 0, officialName);
     params.setValue("h_short_name", 0, shortName);
     }

}
}

function getteamOfficialInfo(XMLDoc, contestant_id, team){
//Extracts teamOfficial info from source
var teamOfficial_path = ‘/matchStats/liveData/lineUp[@contestantId="’+contestant_id+‘"]/teamOfficial’
var teamOfficial = ogscript.runXPath(teamOfficial_path, XMLDoc);
for (var i = 0; i < teamOfficial.length; i++) {
var node = teamOfficial.item(i);
var id = node.getAttribute(‘id’);
var lastName = node.getAttribute(‘lastName’);
var firstName = node.getAttribute(‘firstName’);
var type = node.getAttribute(‘type’);

  if (team=="away"){
  params.setValue("am_id", i, id);
  params.setValue("am_last_name", i, lastName);
  params.setValue("am_first_name", i, firstName);
  params.setValue("am_type", i, type);
  params.setValue("am_full_name", i, firstName+" "+lastName);
  }
  else if (team=="home"){
  params.setValue("hm_id", i, id);
  params.setValue("hm_last_name", i, lastName);
  params.setValue("hm_first_name", i, firstName);
  params.setValue("hm_type", i, type);
  params.setValue("hm_full_name", i, firstName+" "+lastName);
     }

}
}

function getMatchOfficialInfo(XMLDoc){
//Extracts match official info from source
var found = ogscript.runXPath(‘/matchStats/liveData/matchDetailsExtra/matchOfficials/matchOfficial’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var id = node.getAttribute(‘id’);
var firstName = node.getAttribute(‘firstName’);
var lastName = node.getAttribute(‘lastName’);
var type = node.getAttribute(‘type’);

  params.setValue("mo_id", i, id);
  params.setValue("mo_first_name", i, firstName);
  params.setValue("mo_last_name", i, lastName);
  params.setValue("mo_type", i, type);
  params.setValue("mo_full_name", i, firstName+" "+lastName);

}
}

function getMatchInfo(XMLDoc){
//Extracts match info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var id = node.getAttribute(‘id’);

  params.setValue("m_id", i, id);

}
}

function getCompetitionInfo(XMLDoc){
//Extracts competition info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/competition’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);

  params.setValue("m_competition", i, name);

}
}

function getVenueInfo(XMLDoc){
//Extracts venue info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/venue’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var longName = node.getAttribute(‘longName’);

  params.setValue("m_venue", i, longName);

}
}

var XMLDoc = ogscript.parseXML(params.getValue(“rss_feed”, 0));
if (XMLDoc == null) {
ogscript.debug(‘Failed to find source’);
} else {
ogscript.debug(“Found source”);

//Grabbing Team Info
getTeamInfo(XMLDoc);

//Grabbing Player Info
getPlayerInfo(XMLDoc, params.getValue(“h_id”, 0), “home”);
getPlayerInfo(XMLDoc, params.getValue(“a_id”, 0 ), “away”);

//Grabbing teamOfficial Info
getteamOfficialInfo(XMLDoc, params.getValue(“h_id”, 0), “home”);
getteamOfficialInfo(XMLDoc, params.getValue(“a_id”, 0 ), “away”);

//Grabbing matchOfficial Info
getMatchOfficialInfo(XMLDoc);

//Grabbing match Info
getMatchInfo(XMLDoc);

//Grabbing competition Info
getCompetitionInfo(XMLDoc);

//Grabbing venue Info
getVenueInfo(XMLDoc);

}


//Emptying team stats
//Away stats
params.setValue(“a_id”, 0, null);
params.setValue(“a_code”, 0, null);
params.setValue(“a_name”, 0, null);
params.setValue(“a_official_name”, 0, null);
params.setValue(“a_short_name”, 0, null);
params.setValue(“ac_full_name”, 0, null);
params.setValue(“a_logo”, 0, null);
//Home stats
params.setValue(“h_id”, 0, null);
params.setValue(“h_code”, 0, null);
params.setValue(“h_name”, 0, null);
params.setValue(“h_official_name”, 0, null);
params.setValue(“h_short_name”, 0, null);
params.setValue(“hc_full_name”, 0, null);
params.setValue(“h_logo”, 0, null);

//Emptying player stats
var empty = new Array();
//Away stats
params.setAllValues(“ap_id”, empty);
params.setAllValues(“ap_first_name”, empty);
params.setAllValues(“ap_formation”, empty);
params.setAllValues(“ap_last_name”, empty);
params.setAllValues(“ap_match_name”, empty);
params.setAllValues(“ap_position”, empty);
params.setAllValues(“ap_position_side”, empty);
params.setAllValues(“ap_shirt_num”, empty);
params.setAllValues(“ap_full_name”, empty);
params.setAllValues(“ap_custom_text”, empty);

params.setValue(“ap_full_name”, 0, null);
params.setValue(“ap_full_name”, 1, null);
params.setValue(“ap_full_name”, 2, null);
params.setValue(“ap_full_name”, 3, null);
params.setValue(“ap_full_name”, 4, null);
params.setValue(“ap_full_name”, 5, null);
params.setValue(“ap_full_name”, 6, null);
params.setValue(“ap_full_name”, 7, null);
params.setValue(“ap_full_name”, 8, null);
params.setValue(“ap_full_name”, 9, null);
params.setValue(“ap_full_name”, 10, null);
params.setValue(“ap_full_name”, 11, null);
params.setValue(“ap_full_name”, 12, null);
params.setValue(“ap_full_name”, 13, null);
params.setValue(“ap_full_name”, 14, null);
params.setValue(“ap_full_name”, 15, null);
params.setValue(“ap_full_name”, 16, null);
params.setValue(“ap_full_name”, 17, null);
params.setValue(“ap_full_name”, 18, null);
params.setValue(“ap_full_name”, 19, null);

params.setValue(“ap_shirt_num”, 0, null);
params.setValue(“ap_shirt_num”, 1, null);
params.setValue(“ap_shirt_num”, 2, null);
params.setValue(“ap_shirt_num”, 3, null);
params.setValue(“ap_shirt_num”, 4, null);
params.setValue(“ap_shirt_num”, 5, null);
params.setValue(“ap_shirt_num”, 6, null);
params.setValue(“ap_shirt_num”, 7, null);
params.setValue(“ap_shirt_num”, 8, null);
params.setValue(“ap_shirt_num”, 9, null);
params.setValue(“ap_shirt_num”, 10, null);
params.setValue(“ap_shirt_num”, 11, null);
params.setValue(“ap_shirt_num”, 12, null);
params.setValue(“ap_shirt_num”, 13, null);
params.setValue(“ap_shirt_num”, 14, null);
params.setValue(“ap_shirt_num”, 15, null);
params.setValue(“ap_shirt_num”, 16, null);
params.setValue(“ap_shirt_num”, 17, null);
params.setValue(“ap_shirt_num”, 18, null);
params.setValue(“ap_shirt_num”, 19, null);

params.setValue(“ap_custom_text”, 0, null);
params.setValue(“ap_custom_text”, 1, null);
params.setValue(“ap_custom_text”, 2, null);
params.setValue(“ap_custom_text”, 3, null);
params.setValue(“ap_custom_text”, 4, null);
params.setValue(“ap_custom_text”, 5, null);
params.setValue(“ap_custom_text”, 6, null);
params.setValue(“ap_custom_text”, 7, null);
params.setValue(“ap_custom_text”, 8, null);
params.setValue(“ap_custom_text”, 9, null);
params.setValue(“ap_custom_text”, 10, null);
params.setValue(“ap_custom_text”, 11, null);
params.setValue(“ap_custom_text”, 12, null);
params.setValue(“ap_custom_text”, 13, null);
params.setValue(“ap_custom_text”, 14, null);
params.setValue(“ap_custom_text”, 15, null);
params.setValue(“ap_custom_text”, 16, null);
params.setValue(“ap_custom_text”, 17, null);
params.setValue(“ap_custom_text”, 18, null);
params.setValue(“ap_custom_text”, 19, null);
//Home stats
params.setAllValues(“hp_id”, empty);
params.setAllValues(“hp_first_name”, empty);
params.setAllValues(“hp_formation”, empty);
params.setAllValues(“hp_last_name”, empty);
params.setAllValues(“hp_match_name”, empty);
params.setAllValues(“hp_position”, empty);
params.setAllValues(“hp_position_side”, empty);
params.setAllValues(“hp_shirt_num”, empty);
params.setAllValues(“hp_full_name”, empty);

params.setValue(“hp_full_name”, 0, null);
params.setValue(“hp_full_name”, 1, null);
params.setValue(“hp_full_name”, 2, null);
params.setValue(“hp_full_name”, 3, null);
params.setValue(“hp_full_name”, 4, null);
params.setValue(“hp_full_name”, 5, null);
params.setValue(“hp_full_name”, 6, null);
params.setValue(“hp_full_name”, 7, null);
params.setValue(“hp_full_name”, 8, null);
params.setValue(“hp_full_name”, 9, null);
params.setValue(“hp_full_name”, 10, null);
params.setValue(“hp_full_name”, 11, null);
params.setValue(“hp_full_name”, 12, null);
params.setValue(“hp_full_name”, 13, null);
params.setValue(“hp_full_name”, 14, null);
params.setValue(“hp_full_name”, 15, null);
params.setValue(“hp_full_name”, 16, null);
params.setValue(“hp_full_name”, 17, null);
params.setValue(“hp_full_name”, 18, null);
params.setValue(“hp_full_name”, 19, null);

params.setValue(“hp_shirt_num”, 0, null);
params.setValue(“hp_shirt_num”, 1, null);
params.setValue(“hp_shirt_num”, 2, null);
params.setValue(“hp_shirt_num”, 3, null);
params.setValue(“hp_shirt_num”, 4, null);
params.setValue(“hp_shirt_num”, 5, null);
params.setValue(“hp_shirt_num”, 6, null);
params.setValue(“hp_shirt_num”, 7, null);
params.setValue(“hp_shirt_num”, 8, null);
params.setValue(“hp_shirt_num”, 9, null);
params.setValue(“hp_shirt_num”, 10, null);
params.setValue(“hp_shirt_num”, 11, null);
params.setValue(“hp_shirt_num”, 12, null);
params.setValue(“hp_shirt_num”, 13, null);
params.setValue(“hp_shirt_num”, 14, null);
params.setValue(“hp_shirt_num”, 15, null);
params.setValue(“hp_shirt_num”, 16, null);
params.setValue(“hp_shirt_num”, 17, null);
params.setValue(“hp_shirt_num”, 18, null);
params.setValue(“hp_shirt_num”, 19, null);

params.setValue(“hp_custom_text”, 0, null);
params.setValue(“hp_custom_text”, 1, null);
params.setValue(“hp_custom_text”, 2, null);
params.setValue(“hp_custom_text”, 3, null);
params.setValue(“hp_custom_text”, 4, null);
params.setValue(“hp_custom_text”, 5, null);
params.setValue(“hp_custom_text”, 6, null);
params.setValue(“hp_custom_text”, 7, null);
params.setValue(“hp_custom_text”, 8, null);
params.setValue(“hp_custom_text”, 9, null);
params.setValue(“hp_custom_text”, 10, null);
params.setValue(“hp_custom_text”, 11, null);
params.setValue(“hp_custom_text”, 12, null);
params.setValue(“hp_custom_text”, 13, null);
params.setValue(“hp_custom_text”, 14, null);
params.setValue(“hp_custom_text”, 15, null);
params.setValue(“hp_custom_text”, 16, null);
params.setValue(“hp_custom_text”, 17, null);
params.setValue(“hp_custom_text”, 18, null);
params.setValue(“hp_custom_text”, 19, null);

//Emptying teamOfficial stats
var empty = new Array();
//Away stats
params.setAllValues(“am_id”, empty);
params.setAllValues(“am_first_name”, empty);
params.setAllValues(“am_last_name”, empty);
params.setAllValues(“am_type”, empty);
params.setAllValues(“am_full_name”, empty);
params.setValue(“am_full_name”, 0, null);
//Home stats
params.setAllValues(“hm_id”, empty);
params.setAllValues(“hm_first_name”, empty);
params.setAllValues(“hm_last_name”, empty);
params.setAllValues(“hm_type”, empty);
params.setAllValues(“hm_full_name”, empty);
params.setValue(“hm_full_name”, 0, null);

//Emptying official stats
var empty = new Array();
//Official stats
params.setAllValues(“mo_id”, empty);
params.setAllValues(“mo_type”, empty);
params.setAllValues(“mo_first_name”, empty);
params.setAllValues(“mo_last_name”, empty);
params.setAllValues(“mo_full_name”, empty);

params.setValue(“mo_full_name”, 0, null);
params.setValue(“mo_full_name”, 1, null);
params.setValue(“mo_full_name”, 2, null);
params.setValue(“mo_full_name”, 3, null);

params.setValue(“mo_type”, 0, null);
params.setValue(“mo_type”, 1, null);
params.setValue(“mo_type”, 2, null);
params.setValue(“mo_type”, 3, null);

//Emptying match details stats
var empty = new Array();
//Match details stats
params.setValue(“m_id”, 0, null);
params.setValue(“m_competition”, 0, null);
params.setValue(“m_round”, 0, null);
params.setValue(“m_venue”, 0, null);
params.setValue(“m_city”, 0, null);
params.setValue(“m_kickoffTime”, 0, null);


































function getPlayerStatsInfo(XMLDoc, contestant_id, team){
//Extracts player stats info from source
var stats_path = ‘/matchStats/liveData/lineUp[@contestantId="’+contestant_id+‘"]/teamStats/stat’
var stats = ogscript.runXPath(stats_path, XMLDoc);
for (var i = 0; i < stats.length; i++) {
var node = stats.item(i);
var totalScoringAtt = node.getAttribute(‘type=(totalScoringAtt)’);
var ontargetScoringAtt = node.getAttribute(‘ontargetScoringAtt’);
var possessionPercentage = node.getAttribute(‘possessionPercentage’);
var wonCorners = node.getAttribute(‘wonCorners’);
var fkFoulLost = node.getAttribute(‘fkFoulLost’);
var totalYellowCard = node.getAttribute(‘totalYellowCard’);
var totalRedCard = node.getAttribute(‘totalRedCard’);

  if (team=="away"){
  params.setValue("sa_shots", i, totalScoringAtt);
  params.setValue("sa_ontarget", i, ontargetScoringAtt);
  params.setValue("sa_possession", i, possessionPercentage);
  params.setValue("sa_corners", i, wonCorners);
  params.setValue("sa_fouls", i, fkFoulLost);
  params.setValue("sa_yellowcards", i, totalYellowCard);
  params.setValue("sa_redcards", i, totalRedCard);
  }
  else if (team=="home"){
  params.setValue("sh_shots", i, totalScoringAtt);
  params.setValue("sh_ontarget", i, ontargetScoringAtt);
  params.setValue("sh_possession", i, possessionPercentage);
  params.setValue("sh_corners", i, wonCorners);
  params.setValue("sh_fouls", i, fkFoulLost);
  params.setValue("sh_yellowcards", i, totalYellowCard);
  params.setValue("sh_redcards", i, totalRedCard);
  }

}
}

function getTeamInfo(XMLDoc){
//Extracts team info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/contestants/contestant’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);
var id = node.getAttribute(‘id’);
var position = node.getAttribute(‘position’);
var code = node.getAttribute(‘code’);
var officialName = node.getAttribute(‘officialName’);
var shortName = node.getAttribute(‘shortName’);

  if (position=="away"){
     params.setValue("a_id", 0, id);
     params.setValue("a_name", 0, name);
     params.setValue("a_code", 0, code);
     params.setValue("a_official_name", 0, officialName);
     params.setValue("a_short_name", 0, shortName);
     
     }
  else if (position=="home"){
     params.setValue("h_id", 0, id);
     params.setValue("h_name", 0, name);
     params.setValue("h_code", 0, code);
     params.setValue("h_official_name", 0, officialName);
     params.setValue("h_short_name", 0, shortName);
     }

}
}

function getMatchInfo(XMLDoc){
//Extracts match info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var id = node.getAttribute(‘id’);

  params.setValue("m_id", i, id);

}
}

var XMLDoc = ogscript.parseXML(params.getValue(“rss_feed”, 0));
if (XMLDoc == null) {
ogscript.debug(‘Failed to find source’);
} else {
ogscript.debug(“Found source”);

//Grabbing Team Info
getTeamInfo(XMLDoc);

//Grabbing PlayerStats Info
getPlayerInfo(XMLDoc, params.getValue(“h_id”, 0), “home”);
getPlayerInfo(XMLDoc, params.getValue(“a_id”, 0 ), “away”);

//Grabbing match Info
getMatchInfo(XMLDoc);

}


//Emptying goal stats
var empty = new Array();
//Goal stats
params.setAllValues(“sa_possession”, empty);
params.setAllValues(“sa_shots”, empty);
params.setAllValues(“sa_ontarget”, empty);
params.setAllValues(“sa_corners”, empty);
params.setAllValues(“sa_fouls”, empty);
params.setAllValues(“sa_yellowcards”, empty);
params.setAllValues(“sa_redcards”, empty);

params.setAllValues(“sh_possession”, empty);
params.setAllValues(“sh_shots”, empty);
params.setAllValues(“sh_ontarget”, empty);
params.setAllValues(“sh_corners”, empty);
params.setAllValues(“sh_fouls”, empty);
params.setAllValues(“sh_yellowcards”, empty);
params.setAllValues(“sh_redcards”, empty);




​

Hi Sam,

I’ve made a number of changes to the panel and appended the source. I’ll explain the major changes below.

Functions no longer need to be passed XMLDoc as an argument
This change doesn’t change anything visually. It is a backend change in how the code is structured. I’ve made the parsed XML document variable available globally. This means we don’t need to pass it to the functions when calling them anymore. It simplifies the code a little bit which makes it easier to read and understand.

There is now an API tag () which contains all of the functions
Previously, all of the functions existed within the Generate button task. I’ve created an API tag within the panel that has all of the functions so they are available globally. This means if you wanted to, you could easily call them from other buttons on your panel.

I removed some code that was clearing the parameters
I noticed you were clearing each index of the arrays individually. This was a lot of extra code in the grid file, and more work for you to maintain. It also leaves empty rows in your table afterwards because the indexes still exist. I’m not sure if there was a reason for these being here. I removed them but if you need them you can certainly add them back.

I decided to restructure the code so it would be easier to understand and make changes. For example, I noticed you have 2 Generate buttons. Now that I have moved all of the functions into the block, you should see that there is very little code remaining in the tasks of these buttons. If you wanted to, you could move the couple lines of code from the second Generate button to the other button to simplify the layout.

Please let me know if you have any questions.

ap_full_name ap_first_name ap_last_name ap_match_name ap_position ap_shirt_num ap_formation hp_full_name hp_first_name hp_last_name hp_match_name hp_position hp_shirt_num hp_formation mo_full_name mo_first_name mo_last_name mo_type mo_id function getPlayerInfo(contestant_id, team){ //Extracts player info from source var players_path = '/matchStats/liveData/lineUp[@contestantId="'+contestant_id+'"]/player' var players = ogscript.runXPath(players_path, XMLDoc); for (var i = 0; i < players.length; i++) { var node = players.item(i); var playerId = node.getAttribute('playerId'); var formationPlace = node.getAttribute('formationPlace'); var positionSide = node.getAttribute('positionSide'); var shirtNumber = node.getAttribute('shirtNumber'); var matchName = node.getAttribute('matchName'); var lastName = node.getAttribute('lastName'); var firstName = node.getAttribute('firstName'); var position = node.getAttribute('position');
  if (team=="away"){
  params.setValue("ap_id", i, playerId);
  params.setValue("ap_formation", i, formationPlace);
  params.setValue("ap_position_side", i, positionSide);
  params.setValue("ap_shirt_num", i, shirtNumber);
  params.setValue("ap_match_name", i, matchName);
  params.setValue("ap_last_name", i, lastName);
  params.setValue("ap_first_name", i, firstName);
  params.setValue("ap_position", i, position);
  params.setValue("ap_full_name", i, firstName+" "+lastName);
  }
  else if (team=="home"){
  params.setValue("hp_id", i, playerId);
  params.setValue("hp_formation", i, formationPlace);
  params.setValue("hp_position_side", i, positionSide);
  params.setValue("hp_shirt_num", i, shirtNumber);
  params.setValue("hp_match_name", i, matchName);
  params.setValue("hp_last_name", i, lastName);
  params.setValue("hp_first_name", i, firstName);
  params.setValue("hp_position", i, position);
  params.setValue("hp_full_name", i, firstName+" "+lastName);
     }

}
}

function getTeamInfo(){
//Extracts team info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/contestants/contestant’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);
var id = node.getAttribute(‘id’);
var position = node.getAttribute(‘position’);
var code = node.getAttribute(‘code’);
var officialName = node.getAttribute(‘officialName’);
var shortName = node.getAttribute(‘shortName’);

  if (position=="away"){
     params.setValue("a_id", 0, id);
     params.setValue("a_name", 0, name);
     params.setValue("a_code", 0, code);
     params.setValue("a_official_name", 0, officialName);
     params.setValue("a_short_name", 0, shortName);
     
     }
  else if (position=="home"){
     params.setValue("h_id", 0, id);
     params.setValue("h_name", 0, name);
     params.setValue("h_code", 0, code);
     params.setValue("h_official_name", 0, officialName);
     params.setValue("h_short_name", 0, shortName);
     }

}
}

function getteamOfficialInfo(contestant_id, team){
//Extracts teamOfficial info from source
var teamOfficial_path = ‘/matchStats/liveData/lineUp[@contestantId="’+contestant_id+‘"]/teamOfficial’
var teamOfficial = ogscript.runXPath(teamOfficial_path, XMLDoc);
for (var i = 0; i < teamOfficial.length; i++) {
var node = teamOfficial.item(i);
var id = node.getAttribute(‘id’);
var lastName = node.getAttribute(‘lastName’);
var firstName = node.getAttribute(‘firstName’);
var type = node.getAttribute(‘type’);

  if (team=="away"){
  params.setValue("am_id", i, id);
  params.setValue("am_last_name", i, lastName);
  params.setValue("am_first_name", i, firstName);
  params.setValue("am_type", i, type);
  params.setValue("am_full_name", i, firstName+" "+lastName);
  }
  else if (team=="home"){
  params.setValue("hm_id", i, id);
  params.setValue("hm_last_name", i, lastName);
  params.setValue("hm_first_name", i, firstName);
  params.setValue("hm_type", i, type);
  params.setValue("hm_full_name", i, firstName+" "+lastName);
     }

}
}

function getMatchOfficialInfo(){
//Extracts match official info from source
var found = ogscript.runXPath(‘/matchStats/liveData/matchDetailsExtra/matchOfficials/matchOfficial’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var id = node.getAttribute(‘id’);
var firstName = node.getAttribute(‘firstName’);
var lastName = node.getAttribute(‘lastName’);
var type = node.getAttribute(‘type’);

  params.setValue("mo_id", i, id);
  params.setValue("mo_first_name", i, firstName);
  params.setValue("mo_last_name", i, lastName);
  params.setValue("mo_type", i, type);
  params.setValue("mo_full_name", i, firstName+" "+lastName);

}
}

function getMatchInfo(){
//Extracts match info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var id = node.getAttribute(‘id’);

  params.setValue("m_id", i, id);

}
}

function getCompetitionInfo(){
//Extracts competition info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/competition’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var name = node.getAttribute(‘name’);

  params.setValue("m_competition", i, name);

}
}

function getVenueInfo(){
//Extracts venue info from source
var found = ogscript.runXPath(‘/matchStats/matchInfo/venue’, XMLDoc);
for (var i = 0; i < found.length; i++) {
var node = found.item(i);
var longName = node.getAttribute(‘longName’);

  params.setValue("m_venue", i, longName);

}
}

function loadTheXML(){

XMLDoc = ogscript.parseXML(params.getValue(“rss_feed”, 0));
if (XMLDoc == null) {
ogscript.debug(‘Failed to find source’);
} else {
ogscript.debug(“Found source”);
ogscript.putObject(‘myXML’,XMLDoc);
}
}

function getPlayerStatsInfo(contestant_id, team){
//Extracts player stats info from source
var stats_path = ‘/matchStats/liveData/lineUp[@contestantId="’+contestant_id+‘"]/teamStats/stat’
var stats = ogscript.runXPath(stats_path, XMLDoc);
for (var i = 0; i < stats.length; i++) {
var node = stats.item(i);
var type = node.getAttribute(‘type’);
var value = node.getTextContent();

  if (team=="away"){
     switch(type) {
       case "totalScoringAtt":
         params.setValue("sa_shots", 0, value);
         break;
       case "ontargetScoringAtt":
         params.setValue("sa_ontarget", 0, value);
         break;
       case "possessionPercentage":
         params.setValue("sa_possession", 0, value);
         break;
       case "wonCorners":
         params.setValue("sa_corners", 0, value);
         break;
       case "fkFoulLost":
         params.setValue("sa_fouls", 0, value);
         break;
       case "totalYellowCard":
         params.setValue("sa_yellowcards", 0, value);
         break;
       case "totalRedCard":
         params.setValue("sa_redcards", 0, value);
         break;
       default:
         //ogscript.debug("stat "+type+" not found in case statement");
     }
  }
  else if (team=="home"){
     switch(type) {
       case "totalScoringAtt":
         params.setValue("sh_shots", 0, value);
         break;
       case "ontargetScoringAtt":
         params.setValue("sh_ontarget", 0, value);
         break;
       case "possessionPercentage":
         params.setValue("sh_possession", 0, value);
         break;
       case "wonCorners":
         params.setValue("sh_corners", 0, value);
         break;
       case "fkFoulLost":
         params.setValue("sh_fouls", 0, value);
         break;
       case "totalYellowCard":
         params.setValue("sh_yellowcards", 0, value);
         break;
       case "totalRedCard":
         params.setValue("sh_redcards", 0, value);
         break;
       default:
         //ogscript.debug("stat "+type+" not found in case statement");
     }
  }

}
}

var XMLDoc;

//Parse the XML and store it globally loadTheXML();

//Grabbing Team Info
getTeamInfo();

//Grabbing Player Info
getPlayerInfo(params.getValue(“h_id”, 0), “home”);
getPlayerInfo(params.getValue(“a_id”, 0 ), “away”);

//Grabbing teamOfficial Info
getteamOfficialInfo(params.getValue(“h_id”, 0), “home”);
getteamOfficialInfo(params.getValue(“a_id”, 0 ), “away”);

//Grabbing matchOfficial Info
getMatchOfficialInfo();

//Grabbing match Info
getMatchInfo();

//Grabbing competition Info
getCompetitionInfo();

//Grabbing venue Info
getVenueInfo();


//Emptying team stats
//Away stats
params.setValue(“a_id”, 0, null);
params.setValue(“a_code”, 0, null);
params.setValue(“a_name”, 0, null);
params.setValue(“a_official_name”, 0, null);
params.setValue(“a_short_name”, 0, null);
params.setValue(“ac_full_name”, 0, null);
params.setValue(“a_logo”, 0, null);
//Home stats
params.setValue(“h_id”, 0, null);
params.setValue(“h_code”, 0, null);
params.setValue(“h_name”, 0, null);
params.setValue(“h_official_name”, 0, null);
params.setValue(“h_short_name”, 0, null);
params.setValue(“hc_full_name”, 0, null);
params.setValue(“h_logo”, 0, null);

//Emptying player stats
var empty = new Array();
//Away stats
params.setAllValues(“ap_id”, empty);
params.setAllValues(“ap_first_name”, empty);
params.setAllValues(“ap_formation”, empty);
params.setAllValues(“ap_last_name”, empty);
params.setAllValues(“ap_match_name”, empty);
params.setAllValues(“ap_position”, empty);
params.setAllValues(“ap_position_side”, empty);
params.setAllValues(“ap_shirt_num”, empty);
params.setAllValues(“ap_full_name”, empty);
params.setAllValues(“ap_custom_text”, empty);

//Home stats
params.setAllValues(“hp_id”, empty);
params.setAllValues(“hp_first_name”, empty);
params.setAllValues(“hp_formation”, empty);
params.setAllValues(“hp_last_name”, empty);
params.setAllValues(“hp_match_name”, empty);
params.setAllValues(“hp_position”, empty);
params.setAllValues(“hp_position_side”, empty);
params.setAllValues(“hp_shirt_num”, empty);
params.setAllValues(“hp_full_name”, empty);

//Emptying teamOfficial stats
var empty = new Array();
//Away stats
params.setAllValues(“am_id”, empty);
params.setAllValues(“am_first_name”, empty);
params.setAllValues(“am_last_name”, empty);
params.setAllValues(“am_type”, empty);
params.setAllValues(“am_full_name”, empty);
params.setValue(“am_full_name”, 0, null);
//Home stats
params.setAllValues(“hm_id”, empty);
params.setAllValues(“hm_first_name”, empty);
params.setAllValues(“hm_last_name”, empty);
params.setAllValues(“hm_type”, empty);
params.setAllValues(“hm_full_name”, empty);
params.setValue(“hm_full_name”, 0, null);

//Emptying official stats
var empty = new Array();
//Official stats
params.setAllValues(“mo_id”, empty);
params.setAllValues(“mo_type”, empty);
params.setAllValues(“mo_first_name”, empty);
params.setAllValues(“mo_last_name”, empty);
params.setAllValues(“mo_full_name”, empty);

//Emptying match details stats
var empty = new Array();
//Match details stats
params.setValue(“m_id”, 0, null);
params.setValue(“m_competition”, 0, null);
params.setValue(“m_round”, 0, null);
params.setValue(“m_venue”, 0, null);
params.setValue(“m_city”, 0, null);
params.setValue(“m_kickoffTime”, 0, null);


































getPlayerStatsInfo(params.getValue(“h_id”, 0), “home”);
getPlayerStatsInfo(params.getValue(“a_id”, 0 ), “away”);


params.setValue(“sa_possession”, 0, null);
params.setValue(“sa_shots”, 0, null);
params.setValue(“sa_ontarget”, 0, null);
params.setValue(“sa_corners”, 0, null);
params.setValue(“sa_fouls”, 0, null);
params.setValue(“sa_yellowcards”, 0, null);
params.setValue(“sa_redcards”, 0, null);

params.setValue(“sh_possession”, 0, null);
params.setValue(“sh_shots”, 0, null);
params.setValue(“sh_ontarget”, 0, null);
params.setValue(“sh_corners”, 0, null);
params.setValue(“sh_fouls”, 0, null);
params.setValue(“sh_yellowcards”, 0, null);
params.setValue(“sh_redcards”, 0, null);




​

Thanks Dave, this has made it a lot easier for me to understand and make changes.

The reason I set it up the clear the arrays individually was if the data needed to be added manually. When you clear the boxes remain rather than disappearing all together. For certain matches there might not be an api so adding the extra code was my solution.

Not sure if there’s a cleaner way to do this so the rows are not cleared.

And the stats will be on a different tab to the match details/team lists. That’s why there is an additional generate button.