GenoPro Home
GenoPro Home  |  Get Started With My Genealogy Tree  |  Buy  |  Login  |  Privacy  |  Search  |  Site Map
 
JScript help with 'collections'


https://support.genopro.com/Topic21375.aspx
Print Topic | Close Window

By jcguasp - Tuesday, April 15, 2008
This post is, I suppose, directed to Ron because JScript programming related.
I'm trying to create a utility (similar to 'Display all Comments') regarding display of 'all Multi-Language Fields'.
If I was a 'JScript' guru, it would surely be done by now but I'm not. I also read some WWW Ref sites articles but I couln't found any clear explanations of what I would like to achieve.
For info, I used to be fully conversant for manipulating fields associated with 'relational databases' such as Foxpro. Having said that, I don't master at all your 'Collections' even after reading you various SDK help articles.
What I'm trying to do is to access some fields names (and values) in your various collections.
Say each Ind record in the Ind collection has many fields: name.first, birth.date, birth.place, ...
Question: Is it possible to access these fields, one by one, in order to process them in a loop, e.g.
field(1).name = name.first  ; field(1).value = "Jean-Claude" ; field(1).type = string/text (say the 1st field in an Ind record)
field(2).name = birth.date  ; field(2).value = "7 Mar 1950" ; field(2).type = date
field(3).name = birth.place ; field(3).value = "Paris" ; field(3).type = string/text
... and so on, till the field().count (the last field in that Ind record).
You'll probably have to substitute the words 'record' and 'field' to suit your 'collection' language, i.e. keys and whatever.
The above is perhaps a bit simplistic but I really would like to know if it is achievable! At the moment I cannot 'visualize' the structure of a collection, compared to a database with clear records (rows) and fields (columns).
Thank you.
JC
By jcmorin - Tuesday, April 15, 2008
My understanding of your question is: "Can you enumerate all the properties or fields for a given object".

To the best of my knowlegde, the answer is NO. The properties of an object are listed in the Tag Definition dialog, where each tab displays the property of the selected object (individual, family, picture, occupation, source, ...).

For instance, if you wish to write the name and birth date of every individuals you could use the following code:

for (var i = 0; i < Individuals.Count; i++)
{
  var ind = Individuals(i);
  if (!ind.IsDead) // Exclude any individual deceased
  {
     // The individual is alive, so fetch his/her birthday
     var strBirthday = ind.Birthday.ToString("MMMM d");
     if (strBirthday != "")
     {
        Report.Write3Br("<br/><b>", strBirthday, "</b>");
        // Write the name of the individual in the page
        Report.WriteBr(ind.Name);
      }
   }
}


This example has been slightly modified from the build-in skin "Birthday Listing" in GenoPro
By GenoProSupport - Tuesday, April 15, 2008
The only way to get all the fields is to extract the XML and parse the XML content.  This is what Ron did for displaying the custom tags in the Narrative Report.
By genome - Wednesday, April 16, 2008
If you just want to obtain the values from a predefined list of fields then you can using a GenoObject's TagValue method to get its value.

The following script will create a two dimensional array of records and fields, with each field createed an a javascript object having a name and value property. It then displays the data into the GenoPro Message Log. (but note that genopro skips duplicate messages in the log). The fields to be selected are preset in the array fieldnames.

<%[
var fieldnames = new Array('Name', 'Name.Display','Name.First', 'Name.Middle', 'Name.Last','MyCustomTag'); // create list of required fields (change as required)
var i, records=new Array(Individuals.Count);
for (var iCnt = 0; iCnt < Individuals.Count; iCnt++) {               // loop over Individuals collection
 records[iCnt] = new Array();
 i = Individuals(iCnt);
 for (fCnt in fieldnames) {
 records[iCnt][fCnt] = new Object();
  try {                                                                           // trap error when Custom tag field does not exist for this record
   records[iCnt][fCnt].name = fieldnames[fCnt];                    // store field name
   records[iCnt][fCnt].value = i.TagValue(fieldnames[fCnt]);   // store field contents
  } catch(e) {
  // Report.LogError(e.description);
  }
 }
 Report.LogWarning('Data for ' + i.Name);
 for (var fCnt in records[iCnt]) {       // display selected field for each Individual
  Report.LogWarning('  '+records[iCnt][fCnt].name + '=' + records[iCnt][fCnt].value);
 }
}
Report.AbortReport();
]%>

Collections can be considered as sets of records, with properties of each object/record in the collection corresponding to fields or 'tags'. Some of the 'fields' i.e. custom tags are optional and may not appear in all records.

By GenoProSupport - Wednesday, April 16, 2008
Ron is a very smart man.
By jcguasp - Wednesday, April 16, 2008
Thank you all but I gave up.

As I said, I cannot properly 'visualize' how a collection is built/structured so there's no point in continuing further.

Thanks again,

JC

By jcguasp - Monday, April 21, 2008
I finally didn't give up because I don't like unfinished business.
I produced the attached file but it's far from perfect. This utility jscript will allow Users interested in Multi-Linguistic Fields (MLFs) to check-up their fields.
After realizing that tags cannot easily be accessible/enumerated from collections, I added some 'Tags Arrays', as seen on Ron's code, based on the Tag Definitions panel tabs.
I selected some 'Text' fields which should be candidate for MLFs. I hope I didn't forget any!

Various obs noticed during the script implementation:
1) The 'Unions' collection is not supported. In order to enumerate the Unions MLFs, I created a collection during the 'Families' process. Unless I miss something, this Fam Unions collection should exist, similar to an Ind Edu or Occu.
2) The 'ID' tag of the Emotional Relationships, Social Relationships, Labels, Shapes and Pedigree Links are not generated by Genopro.
3) Picture object: the 'Comment' and 'Description' Tags are the same. One tag, to my opinion, is therefore redundant. I only processed the 'Comment' tag in the attached file as it's the one shown in the Pict layout panel. Also for info, the tag recorded in the .xml file is 'Description'!
4) The Shape 'Position' tag doesn't seem to be supported. It's blank in the report. For the report, I used the 'Position.Points' tag.
5) Regarding the 'Custom Tags' (CTs), I noticed a 'Tag' tag within the Document root object but nothing appears in the report so I suspect this 'Tag' tag feature is not supported/implemented. In consequence, the attached file doesn't include any CTs MLFs.

For the Users using MLFs, extract the .zip file, copy/move the extracted Dir into your Skins Dir and run a report.
I tested the attached with my own tree, including many additional dummy MLFs, and the Report looks fine.
Thank you,
JC

Update: the attached file 12th May 2008

By jcmorin - Monday, April 21, 2008
2) The 'ID' tag of the Emotional Relationships, Social Relationships, Labels, Shapes and Pedigree Links are not generated by Genopro.

GenoPro 2007 does not have a tag ID for those objects.  The rationale is those IDs were unused by GenoPro, since no object would link them.  For instance, it is impossible to create a link to a label or a shape.  The lack of a unique identifier for every object prevents a third party to store the XML in a relational database.

We have fixed this issue for the next version.  The version we are currently using has a dedicated ID for every object - this is a requirement for the collaboration module since we need to compare and merge objects based on the XML content from the client and the master copy on the server.

By genome - Friday, April 25, 2008
jcguasp (4/21/2008)
I finally didn't give up because I don't like unfinished business.

Well done for persevering with this, unless you try, how do you know what you can achieve?

I like a challenge too so I hope you don't mind me messing with your script to add the missing Custom Tag , Tagdata  and Document fields.

I used perhaps a bit of trickery but left one or two cryptic clues in the script. I have only noticed one minor issue: It will also report phrase templates in Document Custom Tags because of the '{?' test. This could be circumvented using a regular expression test instead. I'll leave that for another day or perhaps as an exercise for the reader Smile