April 13, 200916 yr 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
April 13, 200916 yr 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 )
April 13, 200916 yr 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.
April 13, 200916 yr 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, 200916 yr by Guest
April 13, 200916 yr 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
April 13, 200916 yr 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
April 13, 200916 yr 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.
April 13, 200916 yr 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, 200916 yr by Guest
April 13, 200916 yr 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. :(
April 13, 200916 yr 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 April 13, 200916 yr by Guest
Create an account or sign in to comment