Skip to main content

Notifications

Supply chain | Supply Chain Management, Commerce
Answered

Event Handler on SalesAgreementGenerateReleaseorder form

(1) ShareShare
ReportReport
Posted on by 1,883
Hi Experts,
 
I am facing difficulty to hide values on control Deliver_DlvMode in SalesAgreementGenerateReleaseorder form because there datasources SalesCreateReleaseOrderTableTmp and SalesCreateReleaseOrderLineTmp is temp table and DlvMode field is from these tables.
 
I was trying to OnQueryExecuting to just show "X-Factory" from Deliver_DlvMode control by eventhandler as below:
 
   [FormDataSourceEventHandler(formDataSourceStr(SalesAgreementGenerateReleaseOrder, SalesCreateReleaseOrderTableTmp), FormDataSourceEventType::QueryExecuting)]
    public static void SalesCreateReleaseOrderTableTmp_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
    {
       
        
        sender.query().dataSourceName(sender.name()).addRange(fieldnum(SalesCreateReleaseOrderTableTmp,DlvMode)).value("X-Factory");
    }
    
 
After Event Handler build, all fields grey out.
 
I need help how to achieve this.
 
Thanks,
Faiz
  • faiz7049 Profile Picture
    faiz7049 1,883 on at
    Event Handler on SalesAgreementGenerateReleaseorder form
    Thank you Mohamed Amine...
     
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    Mohamed Amine Mahmoudi 9,738 Super User 2024 Season 2 on at
    Event Handler on SalesAgreementGenerateReleaseorder form
    Hi @Faiz,
     
    The way you used is incorrect you must use an event handler for lookup.
    the code below for the header lookup if you want to do it for the lines too you have to create an event handler for the Delivery_Line_DlvMode field with the same logic.
    [FormControlEventHandler(formControlStr(SalesAgreementGenerateReleaseOrder, Delivery_DlvMode), FormControlEventType::Lookup)]
    public static void Delivery_DlvMode_OnLookup(FormControl sender, FormControlEventArgs e)
    {       
    	QueryBuildDataSource	queryBuildDataSource;
    	Query               	query 		= new Query();
    	SysTableLookup      	sysTableLookup  = SysTableLookup::newParameters(tableNum(DlvMode), sender);
            
            // Add the lookup columns
            sysTableLookup.addLookupfield(fieldNum(DlvMode, Code));
            sysTableLookup.addLookupfield(fieldNum(DlvMode, Txt));
    
    	// Add Range
    	queryBuildDataSource                	= query.addDataSource(tableNum(DlvMode));
    	queryBuildDataSource.addRange(fieldnum(DlvMode, Code)).value(queryValue("X-Factory"));
    	sysTableLookup.parmQuery(query);
            // Run the lookup
            sysTableLookup.performFormLookup();
    
            //cancel the call to super() to prevent the system from trying to show 
            //the lookup form twice and cause an error.
            FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;
            cancelableSuperEventArgs.CancelSuperCall();
    }
    Best regards,
    Mohamed Amine MAHMOUDI
  • faiz7049 Profile Picture
    faiz7049 1,883 on at
    Event Handler on SalesAgreementGenerateReleaseorder form
    Hi Anton,
     
    I want Delivery_DlvMode only show "X-Factory" option when SalesAgreementGenerateReleaseorder form open. I do not want want based on itemid on SalesAgreement line.
     
    I am confused because Deliver_DlvMode control datasource is from SalesCreateReleaseOrderTableTmp.
     
    Please give me more suggestions.
     
    Thanks,
    Faiz
     
     
  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 18,788 Super User 2024 Season 2 on at
    Event Handler on SalesAgreementGenerateReleaseorder form
    If I understand correctly, you want to limit the delivery modes that are available when creating a release order. You have to override the lookup of the delivery mode control. In your example, your are filtering the datasource of the form, that's why you don't see any data anymore.
     
    Below is a simple working example (last time I checked) of how to override the lookup of the item field of a sales order. There are many examples online on how to do this.
     
    public class SalesTableEventHandler
    {
    	[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)]
    	public static void SalesLine_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e)
    	{
    		var overrides = SalesTableFormExtensionOverrides::construct();
     
    		_sender.object(fieldNum(SalesLine, ItemId)).registerOverrideMethod(methodStr(FormDataObject, lookup),
    			methodStr(SalesTableFormExtensionOverrides, ItemId_OnLookup), overrides);
    	}
    }
     
    
    public class SalesTableFormExtensionOverrides
    {
    	protected void new()
    	{
    	}
     
    	public static SalesTableFormExtensionOverrides construct()
    	{
    		return new SalesTableFormExtensionOverrides();
    	}
     
    	public void ItemId_OnLookup(FormStringControl _callingControl)
    	{
    		SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(InventTable), _callingControl);
     
    		sysTableLookup.addLookupfield(fieldNum(InventTable, ItemId));
    		sysTableLookup.addLookupfield(fieldNum(InventTable, NameAlias));
     
    		sysTableLookup.performFormLookup();
    	}
    }
     

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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans