Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Deleting related records by script

Featured Replies

I'm having variable results with the attached script. In my database each job may have a load of tasks per employee. When the employee has completed each task they can press a button, run a script and the task is deleted from the list of tasks. They access this button from the 'Job Book' Table which shows the tasks as related records in a portal.

Most of the time, it works beautifully, BUT every now and again it deletes the Main (PARENT) record rather than the Related (CHILD). This causes absolute chaos. Each time it has done it, I have tried to get it to do it again, but it doesn't and our employees always shut it down in a panic and can't remember what they've done.

Is there something I can add to or adjust the script so it doesn't do this ever?

TaskCompleted.pdf

The script is interesting, you have a halt prior to the delete record, really nothing should happen.

Without the halt step, the script will switch to the layout, delete whatever record that layout last had, then return to another layout. I would suggest adding a find to look for the record(s) that need to be deleted. If the task to be deleted is in a portal, have the script more like this:

GoToLayout (tasklayout)

set error capture ( on ) -- so users don't get an error if nothing is found

EnterFindMode, no pause

SetField(ID,get ( scriptparameter ) ) where ID is some bit of data that uniquely identifies this record.

Perform find

If ( get ( foundcount ) > 0 ) -- only delete if record found

delete record

end if

goto previous layout

Now create a button in the portal listing the tasks, I usually make a small trash can. Click on that button, Format->Button... and select the above made script, passing parameter using the relationship for that portal choosing the unique ID.

This method will make sure the selected task will be deleted. Another tip, instead of deleting the record, you could change something in the task to indicate that it has been completed so it will not show up on the portal, but there in case you need to document that it was completed and by whom.

  • Author

Thanks - there shouldn't be a halt - that was where I was testing it!

Actually, originally I didn't want the tasks deleted but every week we run a report that shows everything by Job No (Parent) and include the tasks (CHild) However, if I try to omit the child record because the task box is checked as being completed, it omits the Parent record as well and more confusion reigns. Ideally, I would have liked to keep a record of the tasks but it isn't the end of the world if I don't.

Instead of omitting, create a new field in Tasks called Status, autoenter, "Active". Any new task will automatically have Active in this field. In the Parent, create a calculation field, cActive, "Active", make sure it is a text field. Now in your relationships include these fields and you will only show active tasks in the portal. Add this to your finds in Tasks and you will only find active tasks. Whenever you tire of seeing a task record, set field to something other than Active and it will "disappear".

If your parent goes away whenever you omit a task, it sounds like you are viewing the task via a portal and as omit only omits the record you are on, which is the parent in this situation, you will make the parent disappear, or delete if user hits delete record.

If you are trying to print the tasks for a parent, create a layout based upon task, one task per record. Then create a script to find all tasks for that parent, and print. It is much easier than trying to print a layout based upon parent with tasks shown through a portal.

  • Author

Many thanks - although I resolved deleting the records in a slightly different way, I used your script as a starting point. I decided that it would be too much of a brain drain to undertake your second answer (I have to present this on Monday and it is quite a slow process for me) but I will certainly look at this later.

Once again, thankyou

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.