Share via

confirm button in form using sys framework

Anonymous
2024-03-29T19:57:19+00:00

Hi,

I am Tejeswar,

I'm new to D365 please help me with my requirement.

sys operation framework class to update status of selected draft

record to Confirmed. but the problem is it was updating for all draft record to confirm, I need to update for selected record to confirm and This button should be enabled only for the records where status is draft, Confirmed records should not be allowed to delete or edit.

Contract class:

[DataContractAttribute]

public class TutorialSysOperationDataContract

{

    private TStatus status;

    [DataMember, SysOperationLabel(literalStr("Change Status")),

      SysOperationDisplayOrder("1")]

     public TStatus parmSaleStatus(TStatus _status = status)

    {

        status = _status;

        return status;

    }

}

Service class:

class TutorialSysOperationService extends SysOperationServiceBase

{

    public void process(Set _selectedIds)

    {

        Query query;

        QueryRun qr;

        QueryBuildDataSource qbds;

        TSalesOrder salesOrder;

        Common record;

        query = new Query();

        qbds = query.addDataSource(tableNum(TSalesOrder));

        qr = new QueryRun(query);

        try

        {

            ttsbegin;

            for (int i = 1; i <= _selectedIds.elements(); i++)

            {

                salesOrder = TSalesOrder::find(_selectedIds.item(i));

                if (salesOrder && salesOrder.TStatus == TStatus::Draft)

                {

                    salesOrder.TStatus = TStatus::Confirmed;

                    salesOrder.update();

                    info(strFmt("Sales order %1 confirmed successfully", salesOrder.TSalesID));

                }

            }

            ttscommit;

        }

        catch(Exception::Error)

        {

            throw Error("Selected sales order must have at least one line");

        }

    }

}

Here i got an Error:

Error ClassDoesNotContainMethod: Class 'Set' does not contain a definition for method 'item' and no extension method 'item' accepting a first argument of type 'Set' is found on any extension class.

Controller class:

class TutorialSysOperationController extends SysOperationServiceController

{

    protected void new()

    {

        super(classStr(TutorialSysOperationService), methodStr(TutorialSysOperationService, process), SysOperationExecutionMode::Synchronous);

    }

    public ClassDescription defaultCaption()

    {

        return "Process Job";

    }

    public static TutorialSysOperationController construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)

    {

        TutorialSysOperationController controller;

        controller = new TutorialSysOperationController();

        controller.parmExecutionMode(_executionMode);

        return controller;

    }

    public static void main(Args _args)

    {

        TutorialSysOperationController controller = new TutorialSysOperationController();

        controller.parmArgs(_args);

        controller.parmShowDialog(true);

        controller.startOperation();

    }

}

Thanks in advance.

Microsoft 365 and Office | Install, redeem, activate | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-03-29T21:00:50+00:00

    Hi, thank you for reaching out. My name is Deeksha and I'm a Microsoft user like yourself and I will try to help you as best as I can today.

    Contract Class: [DataContractAttribute] class BConfrimContract { private TSalesOrder salesOrder;

    [DataMember, SysOperationLabel(literalStr("Sales Order")), SysOperationDisplayOrder("1")] public TSalesOrder parmSalesOrder(TSalesOrder _salesOrder = salesOrder) { salesOrder = _salesOrder; return salesOrder; } }

    Service class: class BconfrimService extends SysOperationServiceBase { [SysEntryPointAttribute] public void process(BConfrimContract _contract) { TSalesOrder salesOrder = _contract.parmSalesOrder();

    if (salesOrder && salesOrder.TStatus == TStatus::Draft) { ttsbegin;

    salesOrder.selectForUpdate(true); salesOrder.TStatus = TStatus::Confirmed; salesOrder.update();

    ttscommit; } else { warning("Selected record is not in Draft status and cannot be confirmed."); } } }

    Controller Class: class BConfirmController extends SysOperationServiceController { protected void new() { super(classStr(BconfrimService), methodStr(BconfrimService, process), SysOperationExecutionMode::Synchronous); }

    public void init() { BConfrimContract contract = this.parmDataContract() as BConfrimContract;

    // Enable the button only if the selected record is in Draft status if (contract && contract.parmSalesOrder() && contract.parmSalesOrder(). TStatus == TStatus::Draft) { super(); } else { this.enabled(false); } }

    public ClassDescription defaultCaption() { return "Process Job"; }

    public static BConfirmController construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous) { BConfirmController controller; controller = new BConfirmController(); controller.parmExecutionMode(_executionMode); return controller; }

    public static void main(Args _args) { BConfirmController controller = new BConfirmController(); controller.parmArgs(_args); controller.parmShowDialog(true); controller.startOperation(); } }

    Contract Class: Added parmSalesOrder method to get/set the selected TSalesOrder.

    Service Class: Modified the process method to update only the selected TSalesOrder record to "Confirmed" status if its status is "Draft".

    Controller Class: Added the init method to enable the button only if the selected record is in "Draft" status.

    Try these steps and hopefully, it resolves your issue. In case you need further help or assistance, please let us know. You can also contact Microsoft Support if the problem persists.

    Best regards Deeksha

    Was this answer helpful?

    0 comments No comments