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

Pass data to SysOperation framework via x++ with out prompt

(0) ShareShare
ReportReport
Posted on by 238

Greetings everyone,

I am trying to understand sysoperation frame work on d365FO and want to create a batch proces after any event happens.

I wrote service,controller and datacontract classes. For this system i dont want to show any dialog to user. I want to pass parameters from code.

Here is my service classes and controllers.

class MyAsyncSysOperationController extends SysOperationServiceController
{
   

    protected void new(IdentifierName _methodName)
    {
        super(classStr(MyAsyncSysOperationService),_methodName,SysOperationExecutionMode::Asynchronous);
    }

    public static MyAsyncSysOperationController construct(IdentifierName _methodName,SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Asynchronous)
    {
        MyAsyncSysOperationController controller;
        controller = new MyAsyncSysOperationController(_methodName);
        controller.parmExecutionMode(_executionMode);
        return controller;
    }

        public static void main(Args _args,IdentifierName _methodName)
    {
        MyAsyncSysOperationController controller;
       
        controller = MyAsyncSysOperationController::construct(_methodName);
       
        switch(_methodName)
        {
            case methodStr(MyAsyncSysOperationService,sendPurchLine):
                MyPurchLineDC line;
                PurchLine   purchLine;
                purchLine = _args.record();
                line = controller.getDataContractObject();
                line = MyPurchLine::initFromPurchLine(purchLine);
                break;
            default:
                Info("");
        }

 
    
        controller.parmArgs(_args);
        controller.parmShowDialog(false); 
        controller.parmLoadFromSysLastValue(false);

        controller.startOperation();
        
    }

}

class MyAsyncSysOperationService extends SysOperationServiceBase
{
    public void sendPurchLine(MyPurchLineDC _purchLine)
    {

        // sending data to message queue
        

    }

    public void sendSalesLine(MySalesLine _salesLine)
    {

       // sending data to message queue
        

    }

    public void sendCustTable(MyCustVend _custVend)
    {

       // sending data to message queue
        

    }

}

public static MyPurchLineDC initFromPurchLine(PurchLine _purchLine)
{
	MyPurchLineDC line = new MyPurchLineDC();
	
	// fill data here
	
	return line;
}

When i call my datacontract init method on my service class method sendPurchLine(MyPurchLineDC _purchLine) becomes empty and cant see any data on _purchLine.

line = controller.getDataContractObject();
line = MyPurchLineDC::initFromPurchLine(purchLine);

 Other hand if i fill data at controller class insted of using new everything works fine.

line = controller.getDataContractObject();
line.parmPurchId(purchLine.PurchId);
line.parmLineNum(purchLine.LineNumber);

I know object referance completely changes when i call "new" but is there any way to re set datacontract on the controller. Actuly i am asking is there any way to setDataContractObject();

Also is there anyway to pass args from controler to service class.

Hope could explained my self

Thanks for answers.

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    I assume that your intention when calling MyPurchLine::initFromPurchLine() was to modify the data contract used by the controller, but you don't do it. You create a new contract object (instead of using the one you got from controller.getDataContractObject()), assing it to a local variable and then you never use it for anything.

    You likely wanted something like this:

    case methodStr(MyAsyncSysOperationService, sendPurchLine):
    	PurchLine purchLine = _args.record();
    	MyPurchLineDC line = controller.getDataContractObject() as MyPurchLineDC;
    	line.initFromPurchLine(purchLine);
    	break;

    Obviously, initFromPurchLine() needs to be a static method, if it's going to set values to an instance of MyPurchLineDC class.

    I also noticed a bug in the declaration of your main() method. It should have a single parameter (of type Args); your _methodName parameter should be deleted. You can use _args.parm() to pass the method name into main().

  • Ferhat.S Profile Picture
    238 on at

    Hey Martin thanks for help,

    I couldnt think i can take other parameters via args i will use it for my next codes.

    Yes but the question mark for me we are taking data contract class via .getDataContractObject() method but we are not re setting that object later on. how axapta tracking that object ?

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    When you call getDataContractObject(), the controller gives you a reference to the data contract object that it's using. It's really a reference, not a copy - you both refer to the same object. Therefore if you change something in the object, the controller sees your changes, because you both work with the same object.

    Understanding the difference between value types and reference types is import. Study this topic a bit if you aren't familiar with it. It's not specific to X++.

  • Ferhat.S Profile Picture
    238 on at

    I got it, so i take a reference the object and modify it so service class take that same object. Thanks its realy helpful to understood. My other question is,

    Is there any way to pass parameter except datacontract classes to service for example i want to pass or reach args from my service class is that posible ?

  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Well, I think you technically could use a different parameter profile, but it needs to be either a value type or a serializable class (probably just a data contract class), and I don't see any good reason for doing it. Please don't.

    Take the value or values from Args that you're interested in and put it to a data contract class.

  • Ferhat.S Profile Picture
    238 on at

    I see i am thinking like if i can reach args from service will not need datacontract for my purpose. But as i understand cant reach it out there. Thanks a lot Martin.

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
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 384 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans