Announcements
Hi
I am working on a task where I need to change the behaviour of a form control- OneTime (checkbox form control) exist on LogisticsPostalAddress. My requirement is when I open this form then the OneTime control must be checked bydefault & non-editable.
For this I have write an OnIntialzed Event Handler on form to get this behaviour when form will first open.
I have write this code below:
[FormEventHandler(formStr(LogisticsPostalAddress), FormEventType::Initialized)] public static void LogisticsPostalAddress_OnInitialized(xFormRun sender, FormEventArgs e) { FormRun element = sender as FormRun; FormControl oneTimeAddress = element.design().controlName(formControlStr(LogisticsPostalAddress,OneTime)); oneTimeAddress = NoYes::Yes; // throwing type error oneTimeAddress.allowEdit(false); }
This code is working fine & make chechbox non-editable but not getting the idea how to set its value to checked as this control is not bound to any datasource & I have tried :
oneTimeAddress = NoYES::YES, but that is obviously throwing type error. then how to set its value as its a form control type.
I am using the current version D365 F&O.
Thanks & Regards,
Dinesh
Hi Mohit,
The issue gets resolved. It was some system Error.
Thanks,
Dinesh
Hi Mohit,
I have wrote COC for updated control method but getting error on UI side when I clicked on MenuItemButton. The error is: Object Reference not set an instance of an object. Is this issue related to getting formRun. If yes, How to get the formRun in Class COC.
[ExtensionOf(classStr(LogisticsPostalAddressFormEventHandler))] public static final class HSHTLogisticsPostalAddressFormEventHandlerClass_Extension { public static void updatedControls(FormRun _formRun) { next updatedControls(_formRun); FormCheckBoxControl oneTimeControl = _formRun.design().controlName(formControlStr(LogisticsPostalAddress, OneTime)); if (oneTimeControl) { oneTimeControl.checked(true); oneTimeControl.allowEdit(false); } } }
Thanks,
Dinesh
Yes, please create CoC or event handler on updatedControl method and change oneTime checkbox value back to 1. This should work but you need to test if its impacting any functionality specific to oneTime checkbox.
Hi Mohit,
I have debug that code again & found that after that form init COC, this updatedControl method is being called which changing that checkbox value from 1 to 0 again.
Now Do I need to put my code in UpdatedControl method & need to write COC for updatedControl method of this LogisticsPostalAddressFormEventHandler class as this method is subscribe to updatedControls event handler of LogisticspostalAddress form.
Could you pls suggest something.
Thanks,
Dinesh
I have debugged and it gets executed line by line and value was changing from 1 to 0 in this method.
Form init is called first and later updateControls is called. Can you provide more information on behavior, which line gets hit and how it's not executed.
Hi Bharani,
I have tried in run method as well on form but its working same as init method. oneTime checkbox gets non-editable but the value set to 0 only.
Thanks,
Dinesh
Hi Mohit,
I Put a breakpoint & debug the code but how to check this updatedControls method execution, means when this method will execute. Because I wrote OnInitialized EH, so I debug that code is executing properly but this updatedControls method is getting hit but not executed, so how can I check its execution line-by-line.
Thanks,
Dinesh
Have you tried the same code suggested by Girish in run method of form?
Like in run method,
Checkbox control.checked(true);
Hi Dinesh, The value of OneTime checkbox would be setting back to Zero after Form is Initialized. Put a breakpoint on updatedControls method of LogisticsPostalAddressFormEventHandler class, find where it is overriding the value and manipulate that code as well.
Hi Girish,
I have tried controlName.Value(1); & tried debug, the value property is getting changed at this line from bydefault false to true.
But on the UI side, it showing unchecked only. But the checkbox getting non-editable using allowEdit property.
I am not getting why its value not changing on form.
[FormEventHandler(formStr(LogisticsPostalAddress), FormEventType::Initialized)]
public static void LogisticsPostalAddress_OnInitialized(xFormRun sender, FormEventArgs e)
{
FormRun element = sender as FormRun;
FormCheckBoxControl oneTimeAddress = element.design().controlName(formControlStr(LogisticsPostalAddress,OneTime));
oneTimeAddress.value(1);
oneTimeAddress.allowEdit(false);
}
Thanks & Regards,
Dinesh
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,186 Super User 2024 Season 2
Martin Dráb 227,996 Super User 2024 Season 2
nmaenpaa 101,148