First of all, let me re-post your code in a readable way and throw away unused variables:
[FormDataSourceEventHandler(formDataSourceStr(WHSLocation, WMSLocation), FormDataSourceEventType::Initialized)]
public static void whsLocation_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
FormRun element = sender.formRun();
FormCheckBoxControl disableLicensPlate = element.design(0).controlName(“WHSLocation_DisableLicensPlate”);
while select wshLocationProfile
if (wshLocationProfile.LocType == ‘VPG’)
The cricual problem is that you’re trying to do the work at a wrong place. You try to set editability for the same field several times and you hope that it’ll set different values for different records, but it’s not how it works. You’re just overwritting the same value.
You need to run the logic for the currently selected record. Use CoC extension of active() methodthe form data source, or handle Activated event.
Also, you should set editability of the data source field, not just an individual control. You can do it in this way:
var dsField = formDataSource.object(fieldNum(WHSLocation, DisableLicensPlate));
dsField.allowEdit(wshLocationProfile.LocType == ‘VPG’);
This also solves the problem that you hard-coded in control name as string. If it was a valid scenario for referring to a control name, you should have used formControlStr() instead of a string.