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 211

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.

  • Ferhat.S Profile Picture
    211 on at
    RE: Pass data to SysOperation framework via x++ with out prompt

    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.

  • Verified answer
    Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: Pass data to SysOperation framework via x++ with out prompt

    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
    211 on at
    RE: Pass data to SysOperation framework via x++ with out prompt

    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 ?

  • Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: Pass data to SysOperation framework via x++ with out prompt

    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
    211 on at
    RE: Pass data to SysOperation framework via x++ with out prompt

    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 ?

  • Verified answer
    Martin Dráb Profile Picture
    225,155 Moderator on at
    RE: X++ SysOperationFrameWork pass data via x++ with out prompt

    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().

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

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,860 Test role Public

#2
Ludwig Reinhard Profile Picture

Ludwig Reinhard Microsoft Employee

#3
Martin Dráb Profile Picture

Martin Dráb 225,155 Moderator

Leaderboard

Product updates

Dynamics 365 release plans