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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Answered

Event Handler on SalesAgreementGenerateReleaseorder form

(2) ShareShare
ReportReport
Posted on by 2,430
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
2.PNG
1.PNG
3.PNG
I have the same question (0)
  • Suggested answer
    Anton Venter Profile Picture
    20,869 Super User 2026 Season 1 on at
    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();
    	}
    }
     
  • faiz7049 Profile Picture
    2,430 on at
    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
     
     
  • Verified answer
    Mohamed Amine Mahmoudi Profile Picture
    26,811 Super User 2026 Season 1 on at
    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
    2,430 on at
    Thank you Mohamed Amine...
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 81 Super User 2026 Season 1

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 66 Super User 2026 Season 1

#3
Sagar Suman Profile Picture

Sagar Suman 58 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans