A new Field on the location Form should be only enableable with a specific location type ?

Hi All

on WHSLocation Form I have added a new FormCehckBoxControl and the requirment is :

  • The new Field on the location Form should be only enableable for locations with a specific location type

  • Determine specific location type

  • Location => location profile => location type = warehouse management parameter => packing location type

tha’ts meaning if the WSHLocationProfile.LocType == ‘VPG’ then should be the checkbox true and the rest false

What i have treid until now but i can’t go forward thus i need help please

[FormDataSourceEventHandler(formDataSourceStr(WHSLocation, WMSLocation), FormDataSourceEventType::Initialized)]
public static void WHSLocation_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
WMSLocation wMSLocation = sender.cursor();
FormDataSource formDataSource = sender.formRun().dataSource(‘WMSLocation’);
FormRun element = sender.formRun();
FormCheckBoxControl disableLicensPlate;

disableLicensPlate= element.design(0).controlName(“WHSLocation_DisableLicensPlate”);

WHSLOCATIONPROFILE wshLocationProfile;
WHSLOCATIONTYPE wshLocationType;

while select wshLocationProfile

{
if(wshLocationProfile.LocType == ‘VPG’)
{
disableLicensPlate.allowEdit(true);

}
else
{
disableLicensPlate.allowEdit(false);
}

}

}

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”);

	WSHLocationProfile wshLocationProfile;

	while select wshLocationProfile
	{
		if (wshLocationProfile.LocType == ‘VPG’)
		{
			disableLicensPlate.allowEdit(true);
		}
		else
		{
			disableLicensPlate.allowEdit(false);
		}
	}
}

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.

It’s a pity to see that this question has already been answered in another forum. Please avoid duplication and if you do it anyway, keep the information in sync. You don’t want to waste time of people that are willing to help you, do you?