Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5704 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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 )

Posted

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.

Posted (edited)

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
Posted

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

Posted

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

Posted (edited)

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
Posted

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. :(

Posted (edited)

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

This topic is 5704 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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