It’s obvious that related details can be added to master record one by one. But there can be cases, when a predefined set of details should be added. Moreover, you can know in advance not only the data inserted into these newly created details, but also the number of records that should be generated as related details.
Let’s consider the Monthly Maintenance Scheduling example. The workflow is the following: you need to register a contract for Monthly Maintenance services. Each contract includes the Start Date and the End Date. So, the task is, in a simple way, to generate monthly visits as related details of the contract. Furthermore, you need to generate one visit per month during the “Start – End” date range specified in the contract.
“Generate Details” custom button
The “Generate Details” custom button can be a solution. This button can be displayed on the Contract form. When it is clicked, the system generates a Visit record for each month automatically. Furthermore, these generated visits are related to the contract record. Also, the number of visits corresponds to the specified date range.
The detailed instructions of the adjustment are listed below:
Step 1. Supporting Formula-Text column.
First of all, create the “GenerateRecordIds” formula-text column in the Contracts table.
This formula displays the string comprising Contract record Id duplicates. Moreover, the number of duplicates is equal to the number of months. Also, you remember that you need to generate one Visit record for each month.
The RecordId() function used in the formula returns the ID of the current Contract record. Pay your attention, that this ID can be found in the record URL. Besides, please, don’t mix this value with the Id column that exists by default among the System Columns in the most of tables.
The RecordId() is assigned by the system and can’t be changed. It is displayed in the record URL only.
Step 2. “# of Details” Summary column.
There is the Many-To-One relation between Visits and Contracts tables. So, in the Contracts table you can add the Summary column calculating the number of related Visits. Let’s name this column “# of Details”. It will be needed for the assignment, that defines the date of the Visit.
Step 3. Dummy-Multi multi-record custom button.
This button will not be displayed to a user, but it must be create it in the Contracts table. The “Dummy-Multi” button allows to generate many visit records in the Visits table, relate these visits to the Contract and assign the Date to each visit.
Please note, that the “Contract” column is the single-reference column created in the Visits table. It refers to the Contracts table. So, the first assignment inserts the “Contract Reg.Number” key column value to the “Contract” reference column of the Visit.
The AdjustMonth function calculates the Date value for each visit incrementally. The second assignment inserts every date value within the contract date range into the “Date” column. Even more, the “Date” column is a column of the Date type created in the Visits table. It keeps a date ,when the visit should be made.
Step 4. “Generate Details” custom button with the Navigate Action.
Also, this action calls the URL of the existing Dummy-Multi custom button. As a result, the Dummy-Multi custom button generates the same number of Visit records as the number of Contract RecordId duplicates listed in the “GenerateRecordsIds” string. Moreover, each generated Visit is related to the Contract and the visit date is inserted to the “Date” column according to the assignment kept in the action activated by the Dummy-Multi custom button.
At the end a user can click on the “Generate Details” button and the monthly visit records will be generated as related details automatically according to the date range specified in the contract.