Thursday, October 5, 2017

Print Management Tool for doing testing (Testing and Development Env) in AX 2012

//Contract Class
[
    DataContractAttribute,
    SysOperationGroupAttribute('Queryfilter', 'Select', '1'),
    SysOperationGroupAttribute('PrintMgmtSettings', 'Print management settings', '2')
]
class San_PrintManagementDataContract
{
    Email                   email;
    PrintMgmtNodeType       modType;
    PrintMgmtDocumentType   docType;
}

[
    DataMemberAttribute,
    SysOperationGroupMemberAttribute('Queryfilter'),
    SysOperationDisplayOrderAttribute('2')
]
public PrintMgmtDocumentType parmDocType(PrintMgmtDocumentType _docType = docType)
{
    docType = _docType;

    return docType;
}

[
    DataMemberAttribute,
    SysOperationGroupMemberAttribute('PrintMgmtSettings'),
    SysOperationDisplayOrderAttribute('1')
]
public Email parmEmail(Email _email = email)
{
    email = _email;

    return email;
}

[
    DataMemberAttribute,
    SysOperationGroupMemberAttribute('Queryfilter'),
    SysOperationDisplayOrderAttribute('1')
]
public PrintMgmtNodeType parmModuleType(PrintMgmtNodeType _modType = modType)
{
    modType = _modType;

    return modType;
}

//Create Batch class

class San_PrintManagementBatch extends SysOperationServiceController
{
    San_PrintManagementDataContract dataParms;
}

protected ClassDescription defaultCaption()
{
    return 'Print management settings update';
}

public void new(IdentifierName _className = '', IdentifierName _methodName = '', SysOperationExecutionMode _executionMode = 0)
{
    super();

    this.parmClassName(_className);
    this.parmMethodName(_methodName);
    this.parmExecutionMode(_executionMode);
}

public static San_PrintManagementBatch construct()
{
    San_PrintManagementBatch printMgmtBatch;

    printMgmtBatch = new San_PrintManagementBatch (classStr(San_PrintManagementBatch ), methodStr(San_PrintManagementBatch , runProcess));

    return printMgmtBatch;
}

public static void main(Args _args)
{
    San_PrintManagementBatch printMgmtBatch;
    ;

    printMgmtBatch = San_PrintManagementBatch ::construct();
    printMgmtBatch.startOperation();
}

public void runProcess(San_PrintManagementDataContract  _data)
{
    Query                           q = new Query();
    QueryRun                        qr;
    QueryBuildDataSource            qbdsPrintMgmtSetting;
    QueryBuildDataSource            qbdsPrintMgmtDoc;

    PrintMgmtSettings               printMgmtSettings;

    // set up query
    qbdsPrintMgmtDoc = q.addDataSource(tableNum(PrintMgmtDocInstance));

    qbdsPrintMgmtSetting = qbdsPrintMgmtDoc.addDataSource(tableNum(PrintMgmtSettings));
    qbdsPrintMgmtSetting.joinMode(JoinMode::InnerJoin);
    qbdsPrintMgmtSetting.relations(false);
    qbdsPrintMgmtSetting.addLink(fieldNum(PrintMgmtDocInstance, RecId), fieldNum(PrintMgmtSettings, ParentId));

    // if a module is selected, filter on that
    if (_data.parmModuleType())
    {
        qbdsPrintMgmtDoc.addRange(fieldNum(PrintMgmtDocInstance, NodeType)).value(queryValue(_data.parmModuleType()));
    }

    // if a document type is selected, filter on that
    if (_data.parmDocType())
    {
        qbdsPrintMgmtDoc.addRange(fieldNum(PrintMgmtDocInstance, DocumentType)).value(queryValue(_data.parmDocType()));
    }

    qr = new QueryRun(q);

    // loop through the query
    while (qr.next())
    {
        // Get the table buffer
        printMgmtSettings = qr.get(tableNum(PrintMgmtSettings));

        // update the settings
        this.updatePrintSettings(printMgmtSettings, _data);
    }
}

private void updatePrintSettings(PrintMgmtSettings _printMgmtSettings, San_PrintManagementDataContract  _dataContract)
{
    PrintMgmtSettings               printMgmtSettingsUpdate;
    SRSPrintDestinationSettings     printDestSettings;

    // if printer settings were found
    if (_printMgmtSettings.PrintJobSettings)
    {
        ttsBegin;
        select forUpdate printMgmtSettingsUpdate where printMgmtSettingsUpdate.RecId == _printMgmtSettings.RecId;

        printDestSettings =  new SRSPrintDestinationSettings(_printMgmtSettings.PrintJobSettings);

        // if an email was set and an updated email was given
        if (printDestSettings.emailTo() && _dataContract.parmEmail())
        {
            printDestSettings.emailTo(_dataContract.parmEmail());
        }

        // update the settings on the record
        printMgmtSettingsUpdate.PrintJobSettings = printDestSettings.pack();
        printMgmtSettingsUpdate.update();
        ttsCommit;
    }
}

//Create Action Menu Item ("San_PrintManagementTool"), Label "Print management tool"


No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...