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.

Do not delete if dependant record?

Featured Replies

Hi,

Is there a way to prohibit deletion of a parent record if there are any children records?

I would like to create a generic script that goes like this :(


$childFieldName = Get (ScriptParameter)



if (count ($childFieldName) = 0)

   Deletion steps

else

   Message ("You can't delete this record because there are some dependancies.")

end if

The only problem I have is counting the number of dependancies.

Thanks

You can Count ( relationship_to_child::field_with_data ). But the fastest way, since you only need to see if there are no records is: IsEmpty ( relationship_to_child::field_with_data )

  • Author

Thanks for the speed tip.

My problem is more on verifying the presence of a child with the name of the related field. I can't pass a string with the name in the IsEmpty() function.

I want to create a generic script that would work for all of my portal.

verifying the presence of a child with the name of the related field

I'm not sure what the above means. Do you mean that you want to ask: "If the value in a parent field exists in a related field in the child table (via this relationship)?"

If so, I would use the List() function. Assuming the child field is named "child_name", and the parent field is named "parent_name". For a "negative" test, ie., true if it isn't found.

Let (

list_names = List ( child relationship::child_name );

not PatternCount ( ¶ & list_names & ¶; ¶ & parent_name & ¶ )

)

[P.S. But really, I don't know exactly what you're asking for. Could you restate with more specifics?]

Edited by Guest

  • Author

Sorry, my post was confusing.

What I wanted is to use the child fieldname from a parent table to check if the parent has dependancies. So I could create a generic script that I could use anywhere in my solution.

Example :(

validateRecordDeletion ($childFieldname) // Script name and definition

{

$childFieldname = Get (ScriptParameter)

$nbChildRecord = count ($childFieldname)// Instead of childTablename::fieldname

if ($nbChildRecord = 0)

Delete record[] // Delete current record

else

Show Custom Dialog ("You can't delete this records. There are some dependancies")

end if

}

If I don't create a generic script, I will need to create a new script for each record type I want to delete from different layout.

Example :

deleteProduct

deleteInvoice

deleteCustomer

... so on

Well if your script parameter explicitly states the field that you are looking for then it should work.

Parameter:

GetField ( "portalchild::ID" )

If [ Get (ScriptParameter) ]

Deletion steps

Else

Message ["You can't delete this record because there are some dependancies."]

End If

I think you're looking for the Evaluate() function.

One caveat when abstracting field names is that if you ever change the name, you'll have to manually change the script parameter as well.

Look at the GetField() function. If you are using version 10, look also at GetFieldName() - this can eliminate hard-coding at the script parameter level.

Sorry, John and David: didn't see your posts before posting.

Edited by Guest

Ah no problem... I didn't even realize the OP was on FM10.

BTW I think that GetFieldName() is one of the best new functions in FM10. :(

  • Author

Thanks I'll give a try to your suggestions.

I will try to use GetFieldName more frequently.

When I'm developing something in any language(C#, FM, VBS, etc.), I'm always trying to create generic methods, functions or script. Unfortunately, FM seems to be the only one in which we can't create easy generic scripts...

Edited by Guest

It's a good cork for a hole in the foot.

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.