I have been very confused about this topic for months:
- How to navigate from a parent form to child form and come back?
- How to navigate from a child form to a new one child form keeping the parent link?
- How to validate child form data before come back in both cases?
How buttons work
First of all, I would like to describe how buttons are working under my understanding, in the case of validation and redirection:
Save and submit button / Save button:
Both buttons have redirection parameter. You can build the URL dynamically, using a list field value and run-time functions. You can't use calculated fields or control values, this is a very important point.
In the case of validation, both buttons can validate data, including list required fields and validation rules in the form.
Save and continue button:
Save and continue button hasn't redirection parameter. After saving data, the action is refresh page and you are in the same form again.
In the case of validation, only list required fields are validated, NOT the rules in the form.
You can redirect as Save and Submit button, Data will be not saved and of course, there is not any validation.
Keeping in mind that only Save & Submit button allow us the whole validation, and the limitations with redirection building (as far as I know), here is the solution:
Parent ID to new child form
To relationship parent and child, you need to pass the parent ID when you redirect to child form. I assume the parent element is previously saved (this is mandatory for my strategy), so parent ID exists in the ID field. The ID argument is included at the end of the URL string, something like that:
NewForm.aspx?: To call a new child form
ParentID: the parameter name to pass in the query string
ID: The element property, in this case, the ID field
I use a button (Save and Submit) called "Nuevo Hijo" to do it in my Parent form, using the dynamic URL in the redirection (sorry in Spanish):
(As shown in the picture, the child list is included in the parent form)
I would like to remark that:
- Data in the parent form will be saved and validated before navigation
- The parent ID will be used to come back and to record it into child list element to make the relationship between parent and child.
Parent ID to an existing child form
In this case, you can not use a button. Instead of it, you select "Edit" from the menu of the selected element in the included Sharepoint list:
You can't pass the Parent ID using this method, but don't worry because you will have recorded it into child element previously.
Working into child form
Storing the Parent ID
The first thing to do into the new child form is to get the Parent ID from the URL string, using a calculated field:
- Formula: you get the parent id value from the URL string using the fn-getquerystring function
- Connected field: the field name into the child list to store the Parent ID
- Formula calculation ONLY in the new mode. Because if you are editing the child you have the Parent ID recorded yet and you will not send from Parent form again.
Save and Submit Button and return to the parent form
When you finish the edition of the new child, perhaps you want to come back to the Parent form. To do it, we use a save and submit button, including a dynamic redirection URL string as:
fn-if(Is New Mode,Site URL/Lists/MyParent/EditForm.aspx?ID=fn-GetQueryString(ParentId),Site URL/Lists/MyParent/EditForm.aspx?ID=Parent_Id)
First of all, there is a conditional function that defines if the form is in a new mode or not, checking the value of Is New Mode Function.
- In case of a new mode, you define the URL taking the Parent ID who is the URL passed from the Parent form fn-GetQueryString(ParentId)
- In case of not a new mode, you define the URL taking the Parent ID from the Parent_Id field value (that you have stored using the calculated field when you was in new mode)
As you are using Save & Submit button, first of all, data validation happens, then saving and finally redirect to the parent form
Save and Submit Button and open a new child form (keeping the parent ID in the URL string)
If you want to open a new child form, you only need to change the destination URL in the previous formulae:
fn-if(Is New Mode,Site URL/Lists/MyChild/NewForm.aspx?ID=fn-GetQueryString(ParentId),Site URL/Lists/MyChild/NewForm.aspx?ID=Parent_Id)
You can repeat this action as much as you want in order to create multiple child elements and finally come back to the parent form.
That's all. Any comments are welcome, of course, this is only an approach, for sure will be better solutions.
Have a nice workflow day!