web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

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

(0) ShareShare
ReportReport
Posted on by

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

}

}

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi,

    First you need to find the relation between "WMSLocation", WHSLocationProfile,WHSLocationType.

    To enable disable button you can write it on datasource "active" method event handler.

    Try the below code.

    [FormDataSourceEventHandler(formDataSourceStr(WHSLocation, WMSLocation), FormDataSourceEventType::OnActivated)]
    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;
        //get location type from WHSLOCATIONPROFILE based on relation between WHSLOCATIONPROFILE & WMSLocation
        select *from wshLocationProfile
            where wshLocationProfile.LOCProfileId == wMSLocation.LOCProfileId;
    
        if(wshLocationProfile.LocType == 'VPG')
        {
            disableLicensPlate.allowEdit(true);
        }
        else
        {
            disableLicensPlate.allowEdit(false);
        }
    }

    Thanks,

    Girish S,

  • Community Member Profile Picture
    on at

    location.JPG

    profile.JPG

    please have look at Photos there is only one relationship between WHSLocationType and WHSLocationProfile 

    i am new in d365 and don't know how i could do with active method event handler. Would you like to show me please ?

    Thanks alot 

     

  • GirishS Profile Picture
    27,827 Moderator on at

    Hi BenOmran,

    I have updated the code in the previous thread - Check that.

    WHSLocationForm - WMSLocation(Datasource) - Events - OnActivated - Right click - Copy event handler - paste the code in your class and add the logic as I mentioned in the previous thread.

    Thanks,

    Girish S.

  • Community Member Profile Picture
    on at

    Hi Girish S,

    Thanks for your answer but in your posted code i don't see any update or changes . Could you have a look once again please ?

    Thanks

  • GirishS Profile Picture
    27,827 Moderator on at

    I have updated the code.

    I will update it again. See below

    [FormDataSourceEventHandler(formDataSourceStr(WHSLocation, WMSLocation), FormDataSourceEventType::OnActivated)]
    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;
        //get location type from WHSLOCATIONPROFILE based on relation between WHSLOCATIONPROFILE & WMSLocation
        select *from wshLocationProfile
            where wshLocationProfile.LOCProfileId == wMSLocation.LOCProfileId;
    
        if(wshLocationProfile.LocType == 'VPG')
        {
            disableLicensPlate.allowEdit(true);
        }
        else
        {
            disableLicensPlate.allowEdit(false);
        }
    }

    Thanks,

    Girish S.

  • Community Member Profile Picture
    on at

    2627.error.JPG0882.error2.JPG

    I have copy and past your updates Code and i got this error ?! 

  • GirishS Profile Picture
    27,827 Moderator on at

    Change it to FormDataSourceEventType::Activated.

    Thanks,

    Girish S.

  • Community Member Profile Picture
    on at
    [deleted]
  • GirishS Profile Picture
    27,827 Moderator on at

    You don't need to location type to location profile select statement.

    select *from wshLocationProfile

    where wshLocationProfile.LOCProfileId == wMSLocation.LOCProfileId;

    Thanks

    Girish S.

  • GirishS Profile Picture
    27,827 Moderator on at

    Hi BenOmran,

    Is the issue got resolved?

    Thanks,

    Girish S.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 456 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans