Are you performing this script via a script trigger?
If so, disable that script trigger and run this script by clicking a button on your layout.
Let me know if that works. (Go to Layout is notorious for tripping any number of different script triggers on either the layout being exited or the layout being entered by the execution of that script step.)
It is performed via a button: Button setup set to 'perform script', Options of current script set to 'pause'.
Set Variable[$K; Value:ValueCount ( $K+1 )]
Set Variable[$K; Value: $K+1 ]
Apologies if that was due to an error on my part in the original thread.
I get an 'This operation cannot be performed because one or more required related records are not available or cannot be created.' warning. Once I press OK the Input record is generated as expected, the endless loop is dealt with but the prescription isn't 'mirrored' in the Druglist_in portal (or anywhere).
In the relationship of Input < Druglist_in I have to allow creation of records in Druglist_in for the fields to appear in the portal in Browse; otherwise they don't appear. I can add any number of records into the Druglist_in portal and if I transfer to another Input record and do the same thing, then come back, the records to appear in Druglist_in under the first Input record.
Portals have the following filters specified:
No portal filters should be needed as far as I can tell form here and portals could keep things from working here. What you show as "filters" look like what should be set up as match fields defined in the relationships in Manage | Database | Relationships.
Set Variable [ $ID; Value:Patient::Prescription_n ]
Go to Layout [ “Input” (Input) ]
Set Field [ Input::_PrescriptionID; $ID ]
Set Variable [ $List; Value:Druglist_rx::__DrugList_rxID ]
Go to Layout [ “Druglist_rx” (Druglist_rx) ]
Set Variable [ $K; Value: $K+1 ]
Exit Loop If [ $K>ValueCount ( $List ) ]
Set Field [ Druglist_in; GetValue ( List (Druglist_rx::__DrugList_rxID) ; $K) ]
Go to Layout [ “L_Patient Copy” (Patient) ]
Notice the two steps in Blue. The first specifies a layout based on DrugList_rx and so New Record/Request creates a new record in that table. Bu the second step attempts to modify the value of a field from Druglist_in. That makes no sense and is the source of the error message that you report.
The first line in blue should be:
Go to Layout ["Druglist_in" ( Druglist_in ) ]
The second line is also incorrect. the calculated value should be: GetValue ( $List ; $K )