Dynamics AX Blog - sysoperation-framework - Page 2

These posts are machine-translated.
Currently, only posts are displayed, which contain the tag »sysoperation-framework« Filter entfernen

SysOperation-Framework: Refresh calling form/formdatasource

Often, a function that has been created based on the SysOperation-framework, is called from a form via a button. Therefore there is the requirement, that the displayed data should be updated in the form after execution.

I like to use the following logic. This assumes that the call of the function is done via a button and thereby the main()-method is triggered.

This refresh is done via a sub-method and could look like this:

private void refreshCallingForm(args _args)
{
    FormRun callerFormRun;
    #Task

    if(_args && _args.caller() && _args.caller() is formRun)
    {
        callerFormRun = _args.caller();
        callerFormRun.task(#taskF5);
    }
}

The call of this method takes place in the mentioned main():

public static void main(Args _args)
{
    TutorialSysOperationController controller;
    SysOperationStartResult sysOperationStartResult;

    controller = new TutorialSysOperationController();
    controller.parmArgs(_args);
    controller.parmExecutionMode(
        SysOperationExecutionMode::Synchronous);

    sysOperationStartResult =
    controller.startOperation();

    controller.refreshCallingForm(_args);
}

Variations of the refreshCallingForm()

Instead of the task()-method of the form, one could also call some methods of the form data source.

Use of ExecuteQuery()

If you use the executeQuery() of the respective FomDataSource, any filters and the data set focus will be lost.

private void refreshCallingForm(args _args)
{
    FormDataSource fds;
    
    if(_args && 
       _args.record() && 
       _args.record().isFormDataSource())
    {
        fds = _args.record().dataSource();
        fds.executeQuery();
    }
}

Use of ReSearch()

private void refreshCallingForm(args _args)
{
    FormDataSource fds;
    
    if(_args && 
       _args.record() && 
       _args.record().isFormDataSource())
    {
        fds = _args.record().dataSource();
        fds.research(true);
    }
}

Use of ReRead()

A reRead() would be conceivable, but in this case only the active record would be updated.

private void refreshCallingForm(args _args)
{
    if(_args && 
       _args.record() && 
       _args.record().isFormDataSource())
    {
        _args.record().reread();
    }
}

 
 

SysOperation-Framework: Lock field in dialog

If you have to lock a dialog field within a SysOperation-framework, which is integrated via a parm method, you can use code like the following (in UIBuilder).

public void postBuild()
{
    DialogField df_SalesId;

    super();

    df_salesId =
    this.bindInfo().getDialogField(
        this.dataContractObject(),
        methodStr(DEV_SalesUpdateDatacontract, parmSalesId));

    if(df_salesId)
    {
        df_salesId.allowEdit(false);
        df_salesId.skip(true);
    }
}

 
 

SysOperation-Framework: Change the properties of a dialog box depending on other dialog boxes

Consider the following scenario: In the dialog of a SysOperation construct, a field must be manipulated depending on other fields, for example, the AllowEdit property should be changed.

Dialog

In the following you will find the code for a DataContract and the corresponding UIBuilder, in which the corresponding program logic is to be installed.

Here, depending on the selection in the Module field, you can either activate the Customer account field or the Vendor account field.

 

DataContract

[DataContractAttribute, SysOperationContractProcessingAttribute(classStr(TutorialSysOperationUIBuilder))]
public class TutorialSysOperationDataContract
{
    ModuleCustVend moduleCustVend;
    CustAccount custAccount;
    VendAccount vendAccount;
}

 

[DataMemberAttribute, SysOperationControlVisibilityAttribute(true), SysOperationDisplayOrderAttribute('1')]
public ModuleCustVend parmModuleCustVend(ModuleCustVend _moduleCustVend = moduleCustVend)
{
    moduleCustVend = _moduleCustVend;

    return moduleCustVend;
}

 

[DataMemberAttribute, SysOperationControlVisibilityAttribute(true), SysOperationDisplayOrderAttribute('2')]
public CustAccount parmCustAccount(CustAccount _custAccount = custAccount)
{
    custAccount = _custAccount;

    return custAccount;
}

 

[DataMemberAttribute, SysOperationControlVisibilityAttribute(true), SysOperationDisplayOrderAttribute('3')]
public VendAccount parmVendAccount(VendAccount _vendAccount = vendAccount)
{
    vendAccount = _vendAccount;

    return vendAccount;
}

 

UIBuilder

public class TutorialSysOperationUIBuilder extends SysOperationAutomaticUIBuilder
{
    DialogField df_ModuleCustVend;
    DialogField df_CustAccount;
    DialogField df_VendAccount;
}

The methods generated by the framework are made accessible in the method build().

This is the first time the modifyDialogFields() method is called, so that the property of the desired field is changed immediately, when the dialog is opened.

public void build()
{
    super();

    df_ModuleCustVend = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TutorialSysOperationDataContract, parmModuleCustVend));
    df_CustAccount = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TutorialSysOperationDataContract, parmCustAccount));
    df_VendAccount = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(TutorialSysOperationDataContract, parmVendAccount));

    this.modifyDialogFields();
}

In the postRun() method, the modify() method of the module field is overridden.

public void postRun()
{
    super();

    // Override modified method
    df_ModuleCustVend.registerOverrideMethod(methodStr(FormComboBoxControl, modified),
                                             methodStr(TutorialSysOperationUIBuilder, moduleCustVend_modified),
                                             this);
}

In this overridden method, we call the modifyDialogFields() method. Here, it is important that the method obtain the correct parameter profile and return the expected AX data type.

private boolean moduleCustVend_modified(FormComboBoxControl _control)
{
    this.modifyDialogFields();

    return _control.modified();
}

The "magic" goes through the modifyDialogFields() method. The fields are enabled or disabled, depending on the value selected in the module field.

private void modifyDialogFields()
{
    df_CustAccount.allowEdit(df_ModuleCustVend.value() == ModuleCustVend::Cust);
    df_VendAccount.allowEdit(df_ModuleCustVend.value() == ModuleCustVend::Vend);
}

Of course, many other properties of dialog boxes can be changed dynamically in the same way.


 
 

SysOperation Framework: Simple class construct with data provider

The code below is a simple class construct for the SysOperation framework.

Datacontract

[DataContractAttribute]
public class TutorialSysOperationDataContract
{
    CustAccount custAccount;
}

 

[DataMemberAttribute]
public CustAccount parmCustAccount(CustAccount _custAccount = custAccount)
{
    custAccount = _custAccount;
    return custAccount;
}

 

Service

class TutorialSysOperationService extends SysOperationServiceBase
{
}

The method runService() is the actual service method. Using the SysEntryPointAttribute attribute, we control here that no further authorization checks are necessary.

[SysEntryPointAttribute(false)]
public void runService(TutorialSysOperationDataContract _dataContract)
{
    info("Done");
}

 
 

SysOperation-Framework: Simple class construct

The following code shows a very simple class construct for the SysOperation framework. Without the Dataprovider and UIBuilder.

Service

class TutorialSysOperationService extends SysOperationServiceBase
{
}

The method runService() is the actual service method. By means of the attribute SysEntryPointAttribute we control here that no further authorization checks are necessary.

[SysEntryPointAttribute(false)]
public void runService()
{
    info("Done");
}

 

Controller

class TutorialSysOperationController extends SysOperationServiceController
{
}

In the new()-method, we link the controller to the service class.

void new()
{
    super();

    this.parmClassName(classStr(TutorialSysOperationService));
    this.parmMethodName(methodStr(TutorialSysOperationService, runService));
}

The main()-method is the classic entry point when the controller is called via a MenuItem.

public static void main(Args _args)
{
    TutorialSysOperationController controller;

    controller = new TutorialSysOperationController();
    controller.parmArgs(_args);

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

    controller.startOperation();
}

 
 

SysOperation-Framework: Asynchronous processing

The SysOperation framework can also be used to execute functions asynchronously. For this, the ExecutionMode is set to SysOperationExecutionMode::Asynchronous.

This makes sense, for example, when a time-intensive action is to be started, but the user does not have to wait for the end of this action and has to be able to continue working on other topics.

However, such asynchronous processing only works if the following criteria are met:

  • The function was integrated as a service
  • This service has been added to the AxClient service group
  • The user has activated the Run Business Operations into CIL option

 
 

Entitle SysOperation classes with the help of code Permissions

If you want to setup the security for a function, which is based on the Sysperation framework, by using a Code permission, the following steps are necessary:

  1. Create classes
  2. Create menu item (for Controller)
  3. Create Code Permission
  4. Add the method, which should be executed by the framework,  to the Server-Node of this code permission
  5. Add tables to Tables-Node if needed
  6. Change property LinkedPermissionObject to your Code Permission-object and property LnkedPermissionType to CodePermission of your above created menu item
  7. Add menu item to a privilege or a duty as needed

Picture: Step 4

Screenshot

More info at  MSDN.


 
 
Pages « 1 2 3 » 

 

 
 
 
Posts of the actual month
April 2024
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
2930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.