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 :
Supply chain | Supply Chain Management, Commerce
Answered

Event Handler on SalesAgreementGenerateReleaseorder form

(2) ShareShare
ReportReport
Posted on by 2,382
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,346 Super User 2025 Season 2 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,382 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,447 Super User 2025 Season 2 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,382 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

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 > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 307 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 67 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans