El_Pablo Posted April 13, 2009 Posted April 13, 2009 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
Fenton Posted April 13, 2009 Posted April 13, 2009 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 )
El_Pablo Posted April 13, 2009 Author Posted April 13, 2009 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.
Fenton Posted April 13, 2009 Posted April 13, 2009 (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 April 13, 2009 by Guest
El_Pablo Posted April 13, 2009 Author Posted April 13, 2009 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
mr_vodka Posted April 13, 2009 Posted April 13, 2009 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
David Jondreau Posted April 13, 2009 Posted April 13, 2009 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.
comment Posted April 13, 2009 Posted April 13, 2009 (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 April 13, 2009 by Guest
mr_vodka Posted April 13, 2009 Posted April 13, 2009 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. :(
El_Pablo Posted April 13, 2009 Author Posted April 13, 2009 (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 April 13, 2009 by Guest
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now