Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Add records to linked form with a form script does not preserve link
- This topic has 3 replies, 2 voices, and was last updated 2 years, 8 months ago by johnny_law.
-
AuthorPosts
-
April 23, 2022 at 6:33 AM #47162
Victor WarnerParticipantIn a post I received a help from Sam Moffat and Brendan on how to create, from one form, a set of records in a linked form with a form script. (The post: https://www.tapforms.com/forums/topic/how-to-add-more-than-one-record-at-a-time-using-a-form-script/).
The script below work correctly (it creates the records in the link). However, only the first record created in the linked form is linked. The others are not linked, and it is necessary to go through them one by one to create the link.
The field linking the two forms is Link to Form, One to Many.
Is there a way to overcome this? Any help would be gratefully received.
The script:
`// Fields from Time Spent form
var order_of_records_id = ‘fld-d78467379e004205b7893109bca23db2’;
var date_of_activity_id = ‘fld-5b07fd9bb7b441848d31de782bcd8780’;
var time_spent_id = ‘fld-be5bcddb8b46426eb90dded15790ef89’;
var activity_id = ‘fld-160340262dbd416291dbeebd7119bd86’;
var description_of_activity_id = ‘fld-c4316e0ee4e7457b92b2f8cc6f699200’;// Date fields
// Add today’s date
var date_signed = new Date();// Formatted to 23/04/2022 for entry in a time entry
var date_signed_formatted = date_signed.toLocaleDateString(“en-GB”, { year: ‘numeric’, month: ‘long’, day: ‘numeric’ })console.log (date_signed + “\n” + date_signed_formatted);
var output = function printOut(continued) {
if (continued == true) {console.log(heshe + ‘\n\n\n’ + date_signed + date_signed_formatted);
let entries = [{
[order_of_records_id]: “1”,
[date_of_activity_id]: new Date(),
[time_spent_id]: “6”,
[activity_id]: “Calls & emails”,
[description_of_activity_id]: “”
},
{
[order_of_records_id]: “2”,
[date_of_activity_id]: new Date(),
[time_spent_id]: “6”,
[activity_id]: “See and identify client”,
[description_of_activity_id]: “See client at [ ] – identify client by ” + heshe + “United Kingdom of Great Britain and Northern Ireland passport and a second form of identification”
},
{
[order_of_records_id]: “3”,
[date_of_activity_id]: new Date(),
[time_spent_id]: “12”,
[activity_id]: “Discuss client’s document(s)/matter, see client sign document(s)”,
[description_of_activity_id]: “Client [ ]\n\nObtain confirmation that:\n\n(i) client has read the Power of attorney, \n\n(ii) the facts and information contained in the Power of attorney are correct,(iii) client is willing to be bound by the Power of attorney; and \n\n(iv) client is willing to grant the power of attorney in favour of the person(s) named in the power of attorney\n\nOn ” + date_signed_formatted + ” at [ ] and [name of client] signed the power of attorney in favour of person named as the attorney in my presence as a deed with myself acting as a witness”
},
{
[order_of_records_id]: “4”,
[date_of_activity_id]: new Date(),
[time_spent_id]: “12”,
[activity_id]: “Notarise document”,
[description_of_activity_id]: “Prepare covering certificate for 1 document (Power of attorney) and attach the covering certificate to the Power of attorney document – bind, seal and sign”
},
{
[order_of_records_id]: “5”,
[date_of_activity_id]: new Date(),
[time_spent_id]: “6”,
[activity_id]: “Arrange for legalisation/apostille”,
[description_of_activity_id]: “Arrange with legalisation agent to collect 1 document (Power of attorney) and then obtain apostille using normal service of the Foreign, Commonwealth and Development Office, and deliver the documents by courier”
},
{
[order_of_records_id]: “6”,
[date_of_activity_id]: new Date(),
[time_spent_id]: “”,
[activity_id]: “Write up notarial register”,
[description_of_activity_id]: “”
}];
for (let entry of entries) {
let newRecord = record.addNewRecordToField(‘fld-d6d2f3fd370a45c2b0d2b281fe012784’);
newRecord.setFieldValues(entry);
}
document.saveAllChanges();
} else {
console.log (“Cancel button pressed.”);}
}
var heshe;
var heshe_list = [‘his’, ‘her’];let prompter = Prompter.new();
prompter.cancelButtonTitle = ‘Cancel’;
prompter.continueButtonTitle = ‘Continue’;
prompter.addParameter(‘He or she: ‘, ‘heshe’, ‘popup’, heshe_list)
.show(‘Choose whether there is a he or she’,output);`
April 26, 2022 at 10:06 AM #47173
johnny_lawParticipantI just started having the same problem with a script I use everyday that programmically adds rows to a child form using the command “ record.addNewRecordToField(id)”
The first time a row is added it is linked to the parent form. The subsequent rows are not.
This broke with the last update I just updated yesterday to version 5.3.24.
Prior to this version it was working great.
Regards,
Johnny
- This reply was modified 2 years, 8 months ago by johnny_law.
April 26, 2022 at 10:52 AM #47175
Victor WarnerParticipantJohnny,
Thank you for posting and confirming that there appears to be a problem with the command.
It would be good for Brendan to let us know whether it is bug.
April 26, 2022 at 6:26 PM #47176
johnny_lawParticipantVictor,
I still think it is a bug introduced in the newest update. However, I started playing around since this is something I use daily and it is 14 records everyday.
I was able to make it work by using the addRecordToField(someRecord,fieldId) method on each row after the row was added and updated.
I have noticed an improvement in other areas dealing with child records were I used to find that some code would not update the child records when I processed them after updating the records. Like a cleanup method. I used to refresh everything by backing out and closing the document and it would work again. A memory refresh. I haven’t had to do that since I updated yesterday.
I hope this helps you. Good luck.
Regards,
Johnny
-
AuthorPosts
You must be logged in to reply to this topic.