The Save srvroutine in the server module, xDepartmentsDataServer has the following logic:
Srvroutine Name(Save)
Group_Map For(*INPUT) Group(#xDepartments)
Field_Map For(*OUTPUT) Field(#io£sts) Parameter_Name(Status)
* Look for an existing record
Check_For In_File(xDepartments) With_Key(#xDepartmentCode)
* Update the record if found, otherwise create a new one
If_Status Is(*EQUALKEY)
Update Fields(#xDepartments) In_File(xDepartments) With_Key(#xDepartmentCode)
Else
Insert Fields(#xDepartments) To_File(xDepartments)
Endif
Endroutine
The Check_For command has a number of other parameters which handle an error and messages. This simple example returns a status code into field IO$STS. As explained earlier, the parameter IO_Status(*status) defines this behavior.
The IF_Status command tests the value of field IO$STS and handles UPDATE or INSERT as required.
This means we can fetch an existing record, change description and Save it.
1. Execute your web page and fetch an existing record with a code of 100, 200 or 1000 for example. Change description and click Save. Fetch the same record to confirm the update.
2. Note that when a department is retrieved, the Department Code field is input capable, meaning we could change the code and Save, creating a new record, provided this record doesn't already exist.
3. Change the Fetch method, to set the field xDepartmentCode's Enabled property to False if the record was retrieved.
Your code should look like the following:
. . .
Evtroutine Handling(#FindDepartment.Completed)
If (#IO£STS = OK)
#xDepartmentCode.enabled := false
Endif
Endroutine
. . .
4. Change the Save method to set the field xDepartmentCode's Enabled property to True, if the record was saved.
. . .
Evtroutine Handling(#SaveDepartment.Completed)
If (#IO£STS = OK)
#xDepartments := *default
#COM_OWNER.Errors( True )
#xDepartmentCode.Enabled := true
Else
#COM_OWNER.Errors( False )
Endif
Endroutine
. . .
5. Compile and test your web page. Ensure that this change is working correctly.