hi guys, this is my first time using master/detail, i have single record form and i want to link different table with grid application as master/detail… i could manage to add it as master detail but it doesn’t show if the record has no id… that is normal, when new record in the form, there is no id yet, so the detail grid doesn’t show… if i save the form and open it in update mode it shows the grid detail!!! i want to be able to add from the main form some detaisl in the grid detail… how this is done? I started to doubt of sc videos really
As usual when you decide to use a different approach you need to insert your own code.In this case you have a few options. In the onbeforeadd/update or onafteradd/update or onvalidateok you can decide to insert a record to your detail manually. Nice to see you back Mike.
oh thanks Albert, wish you happy new year
what kind of code should be added? i want to link the main form id to the detail form (simple grid) first, it doesn’t show at all if main form is insert mode… obviously there is no id linked… but if main form is in update mode then the detail grid shows normally, hence, we need to id of the main form to be generated before the working on the detail one… i don’t see it logic, don’t know
Thanks Albert, happy new year
what code should be added? in the main form or the detail application? i have the main form is single record and the detail one is simple grid… first, detail deosn’t show at all, assuming because the main form is still doesn’t have an id generated… but if open in update mode, then id there , the detail grid shows…
where to add the code? what to add? how we can make the main form generate id before is inserted to work on the detail form?
Hi Mike,
As long as there is no master then there will be no detail. So don’t expect a detail record to show up when you are inserting a master. If you have no keys then same issue.But you can save and then enter edit mode automatically (no need to create a new record after insert, there’s a checkbox in your menu somewhere. Other option is to pre-enter a new record with key(s) but wihtout data and go into updatemode immediately.
hmmmm thanks Alber, well, i don’t want to enter update mode, that is different story… since I want to display this detail form only if one select field value is Yes, then please tell me if this correct approach:
1- remove the detail from from main form A
2- copy the the form to new one (form B) and remove all fields, only keep the id field hidden and add the detail form here linking it to ID field
3- in form A, on afterinsert event if value is Y then sc_redir to form B with passing id field… this way form B will open in update mode after receving the id the detail form should work normally
4- user need to add the data in the detail of form B and submit to compelte
seems like 2 parts form… in case value of one field is Yes then ok next form will show up with its details, if not, then proceed to confirmation message (control application) that to be control application… something like on afterinsert of Form A:
if ({field}==‘Y’)
{
sc_commit();
sc_redir(formB, {id}=[id]); }
else {
sc_redir(control_message);
}
sounds good?
grrrrr i just replied, can you check if my post gone to moderation again?
hmmmm, well, thanks Albert, I don’t want to go into update mode, that is different story.
let me tell you small plan
1- remove the detail from Form A
2- copy form A to form B removing all fields and keep only the detail form there
3- set form B for update mode only to receive a where id=[id]
4- i have control application messge informing user that submission is done
5- and i have field in From A if selected Yes then i want this detail to show, otherwise, proceed to confirmation messge
hence;
in onafterinsert form A something like
if ( {field}==‘Y’)
{
[id]={id};
sc_committ();
sc_redir(formB,[id]=[id]);
}
else
{
sc_committ();
sc_redir(control_message);
}
Sounds good something like 2 parts submission form? if yes, what you think the drawback could be?
Why don’t create “ghost” record, and redirect to there, and manage uncompleted submissions with a flag? I see it more easy
Giu, what is ghost record and how i can do this? any more info to try? I’m working on above steps and still want to know what drawbacks to expect?
I call a ghost record to a “fake” record.
Before you redirect to the form, you create a record, and instead to redir to the form, you redir to the form to this specific record. This way, record exists, and detail is shown. You need to address some way to make sure a record is valid, with a flag on a field, for example (field ghost = 1), and once you consider this record is “valid” on update you put ghost = 0.
drawbacks? Well, is a dirty, but working solution. You have to take into consideration, on grids for example, to avoid ghost = 1 records, to avoid show “uncompleted” records, and you need some kind of cron job, or maintnenance task, to delete ghost records from some minutes/hours ago (to avoid garbage on database).
I hope is more clear.
well, is clear now, i guess my steps said above will also remove the need of opening Form B in case user will not need to select YES, in 90% of the cases user will select NO then no need for Form B in the first place actually, i’m still trying it still didn’t finish… however, i’m really upset of SC people all videos and what I imagined about master detail is working some magic through this, but obviously, it works only in update mode which is logic if you want to link by id which is not existed yet, i wounder how we see a lot of applications over the web and in business that requires opening sub forms while still inserting main form is not submitted, i was thinking this will solve it some how,
btw: i like the called ghost thing i will try it sometime, for now i don’t want to risk testing it and go longer in time especially that will be many users using the same form eventually, so i will need to maintain many ghosts and possibility of ghosts duplication so leads to errors loool
thanks Giu & albert… anybody can add ideas or comments please feel welcome
i wounder how we see a lot of applications over the web and in business that requires opening sub forms while still inserting main form is not submitted
Well, probably because using some ORM and/or UUIDs for ID storage. UUID can be generated from code and used as “FK” and this can’t cause problems, but when using a PK of autonumeric type, value depends of the moment when you do the insert. Another way is to store all this information on a JSON for example, and apply the PK/FK on the moment of the “final save”. You can achieve this on a lot of ways when you have control on the persistence layer, but with SC you are not in this situation
well thanks giu to let us know where we stand that is encouraging