Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › acending or decending order of child record selection
- This topic has 2 replies, 2 voices, and was last updated 6 months, 3 weeks ago by Giovanni Vittoria.
-
AuthorPosts
-
April 22, 2024 at 1:30 AM #50706
Giovanni VittoriaParticipantHi there!
I have a form, in which I collect specific records (certain events) from another (child-)form.
Since the events in the childform are ordered decending (latest events at the top of list), the collected entries in the list of my parentform are also in decending order. When I change the childform to acending order (oldest at top of list), my list in parentform is in ascending order as well. Thats all fine and working properly.
But I would like to have my entries in the childform in decending order, and my list in the parentform in acending order (without changing the order of child records).
How do I have to change my code (in specific: the child records loop) to reach this?
function MSKat1oB() {
var parentform_Children_id = ‘fld-01b5e453dbdf4307a80dae969e113303’;//table of sourcedata (1:n LinkField to ChildForm)
var parentform_Children = record.getFieldValue(parentform_Children_id); //datasets of sourcedatavar childform_AllProperties_id = ‘fld-463670957bf04035b041e13828ff8d9a’;//field of interest of sourcedata
var MSKat_id = ‘fld-1dc9b25824ff44079515077c57b98249’;
var parentform_CollectionOfChildren_id = ‘fld-eab8dce3220f4fd2bd3c9051d9ea6196’;//tagetfield for collected data from field of interest
var anzahl = 0;
var temp_CurrentChild = []; //array for collecting data
//running through all datasets & collecting data into temp. array
for (var index = 0, count = parentform_Children.length; index < count; index++){
var childform_AllProperties = parentform_Children[index].getFieldValue(childform_AllProperties_id);
var MSKat = parentform_Children[index].getFieldValue(MSKat_id);if (MSKat == “1”) {
temp_CurrentChild.push(childform_AllProperties);
anzahl++;
}
}//joining collected data from temp. array into temp. variable
var temp_ChildrenList = temp_CurrentChild.join(“\r####### \r”);//writing joined collection from temp. variable into target field
record.setFieldValue(parentform_CollectionOfChildren_id, (anzahl + ” zugeordnete Schlüsselereignisse \r \r####### \r” + temp_ChildrenList + “\r#######-END-####### \r”));document.saveAllChanges();
return temp_ChildrenList;
}
MSKat1oB();
Thank you so much for your help!
cheers, Giovanni
April 22, 2024 at 10:05 AM #50707
Daniel LeuParticipantThere are two easy options. 1) you reverse the array with all the child records or 2) you traverse that array from the end to the beginning:
1) reverse array
var parentform_Children = record.getFieldValue(parentform_Children_id); //datasets of sourcedata parentform_Children = parentform_Children.reverse(); ...
2) change traverse order
for (var index = parentform_Children.length - 1; index >= 0; index--){ ... }
April 22, 2024 at 12:22 PM #50708
Giovanni VittoriaParticipantThank you so much, Daniel!
Works like a charme :-)
Easy solution (if one knows how to do) ;-)
cheers, Giovanni
-
AuthorPosts
You must be logged in to reply to this topic.