Friday, December 14, 2018

D365FO: Process the logic after exporting data through DMF

[ExtensionOf(classstr(DMFPackageExporter))]
final class AVADMFPackageExportToFile_Extension
{   
    public static SharedServiceUnitFileID exportToFileV2(DMFDefinitionGroupName _definitionGroup, DMFExecutionId _executionId, DMFEntityName _entity, DMFSourceName _sourceFormat, Map _entitySyncVersion, int _previewCount )
    {
        SharedServiceUnitFileID      sourceFilepath;
        DMFDefinitionGroupExecution  _dmfDefinitionGroupExecution;
        DMFEntity                   _dmfEntity = DMFEntity::find(_entity);
        _dmfDefinitionGroupExecution = DMFDefinitionGroupExecution::find(_definitionGroup,_entity,_executionId);
        sourceFilepath = next exportToFileV2(_definitionGroup,_executionId,_entity, _sourceFormat ,_entitySyncVersion ,_previewCount);
        if(_dmfEntity.TargetEntity == 'Your entity name')
        {
            if (_dmfDefinitionGroupExecution.StagingStatus == DMFBatchJobStatus::Finished)
            {
                }
            }
        }
        if(_dmfEntity.TargetEntity == 'AVAResendInventTransferOrderLineEntity')
        {
           
           // write your logic here
           
        }
        return sourceFilepath;
    }

}

Tuesday, November 1, 2016

Testing SSRS report RDP class in Job

static void testSSRSDPCLS(Args _args)
{
    VendInvoiceTmp tempTable;
    VendInvoiceDP dataProvider = new VendInvoiceDP();
    VendInvoiceContract contract = new VendInvoiceContract();
    contract.parmFromDate(systemDateGet()-365);
    contract.parmToDate(systemDateGet());


    dataProvider.parmDataContract(contract);
    dataProvider.processReport();
    tempTable = dataProvider.getVendInvoiceTmp();

    while select tempTable
    {
        info(tempTable.AVAVendName);
        info(tempTable.AccountNum);
    }
}

Monday, October 17, 2016

Fetching current legal entity address

static void AVAgetAddressOnPurposeForLegalEntity(Args _args)
{
    LogisticsAddressing  address;

    ;

    address = DirParty::findPostalAddressByRole(CompanyInfo::current(), LogisticsLocationRoleType::Business).Address;

    info(address);

}

Saving PO report as PDF in the shared path

/// <summary>
/// This method generates the PO Confirmation report.
/// </summary>
/// <param name="_purchTable">
/// Gets the PurchTable buffer.
/// </param>
/// <remarks>
/// Generates the PO Confirmation report.
/// </remarks>

//Begin
private void AVAPOConfrimationReportGeneration(PurchTable _purchTable)
{
    SrsReportRunController          ssrsController = new SrsReportRunController();
    PurchPurchaseOrderContract      Contract = new PurchPurchaseOrderContract();
    SRSPrintDestinationSettings     printerSettings;
    VendPurchOrderJour              VendPurchOrderJrn;
    str                             poReportPath;
    ;

    select firstOnly RecId from VendPurchOrderJrn
    order by VendPurchOrderJrn.createdDateTime DESC
    where VendPurchOrderJrn.PurchId == _purchTable.PurchId;

    poReportPath = PurchParameters::find().AvaPurchOrderPath + '\\'  + _purchTable.PurchId +'.pdf';
    ssrsController.parmReportName(ssrsReportStr(PurchPurchaseOrder, Report));
    ssrsController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
    ssrsController.parmShowDialog(false);
    Contract.parmRecordId(VendPurchOrderJrn.RecId);
    ssrsController.parmReportContract().parmRdpContract(Contract);

    //link the printer settings to the controller
    printerSettings = ssrsController.parmReportContract().parmPrintSettings();
    //print to pdf and always overwrite if the file exists
    printerSettings.printMediumType(SRSPrintMediumType::File);
    printerSettings.fileFormat(SRSReportFileFormat::PDF);
    printerSettings.overwriteFile(true);
    printerSettings.fileName(@poReportPath);

    try
    {
    //run & save the report
    ssrsController.runReport();
    }
    catch(Exception::CLRError)
    {
        //Access the last CLR Exception
        info(CLRInterop::getLastException().ToString());
        AifUtil::getClrErrorMessage();
        //See AifUtil::getClrErrorMessage for another alternative
        //how to parse the Exception object
    }
}
//End

Sending PO report to email

/// <summary>
/// this method has logic to send email
/// </summary>
/// <param name="_vendTable">
/// getting vendor table as parameter
/// </param>
/// <param name="_purchTable">
/// getting purchase order table as parameter
/// </param>
/// <param name="_emailAttachments">
/// getting whether the email checkbox is selected or not as parameter
/// </param>
// Begin
public static void sendEmailSysMailer(VendTable _vendTable, PurchTable _purchTable, NoYes _emailAttachments=NoYes::No)
{
    InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
    SysMailer   sysMailer;
    str         filePathName, reportFilePathName;
    VendTable   vendTable=_vendTable;
    DocuRef     docuRef;
    EmailBase   sender;
    Notes       body;
    ;

    if(_purchTable.RecId)
    {
        sender = SysUserInfo::find(curUserId()).Email;

        permission.assert();
        sysMailer = new SysMailer();

        //reportFilePathName = PurchParameters::find().AvaPurchOrderPath + '\\default.pdf';
        reportFilePathName = PurchParameters::find().AvaPurchOrderPath + '\\' + _purchTable.PurchId +'.pdf';
        // AVAEmailPOConfirmationWithAttachments - Hema - 28/Aug/2016 - Begin
        //Requirement change
        //Attach PO report as external attachment to the PO header and then send it to vendor's email
        AvaSendingEmailPOConfirmation::attachPOReport(_purchTable, reportFilePathName);
        //sysMailer.attachments().add(reportFilePathName);
        // AVAEmailPOConfirmationWithAttachments - Hema - 28/Aug/2016 - End

        if(_emailAttachments == NoYes::Yes)
        {
            //info('Sender email id: ' + sender);
            while select docuRef
                where docuRef.RefRecId    == _purchTable.RecId
                   && docuRef.Restriction == DocuRestriction::External
                   && docuRef.RefTableId  == tableNum(PurchTable)
                {
                    filePathName = docuRef.completeFilename();
                    if( !((docuRef.docuType().TypeGroup == DocuTypeGroup::Note) || (docuRef.docuType().TypeGroup == DocuTypeGroup::URL)))
                    {
                        sysMailer.attachments().add(filePathName);
                    }
                }
            //info('Vendor primary email id: ' +vendTable.email());
            body = 'Please see attached '+ _purchTable.PurchId +' from Golden Spread Electric Cooperative.  Feel free to contact us if you have any questions and concerns.';
            //sysMailer.quickSend("bijan.ghofranian@avanade.com",vendTable.email(),'PO Confirmed '+_purchTable.PurchId,'Your PO '+ _purchTable.PurchId + ' was Confirmed');
            sysMailer.quickSend(sender,vendTable.email(),'PO Confirmed '+_purchTable.PurchId,body);
            info(strFmt("@AVA39",vendTable.email())); //Email sent to %1
            sysMailer.attachments().clear();
        }
        CodeAccessPermission::revertAssert();
    }
}
//End

Attaching PO report as PO header attachment


/// <summary>
/// this method has logic to add po report pdf as external attachment against the POil
/// </summary>
/// <param name="_purchTable">
/// getting purchase order table as parameter
/// </param>
/// <param name="_fileName">
/// getting file name to attach as external attachment as parameter
/// </param>
//Begin
static void attachPOReport(PurchTable _purchTable, Notes _fileName)
{
    DocuRef docuRef;
    DocuActionArchive archive;
    ;

    if (_purchTable!=null)
    {
        try
        {
            docuRef.clear();
            docuRef.RefRecId = _purchTable.RecId;
            docuRef.RefTableId = tableNum(PurchTable);
            docuRef.RefCompanyId = curext();
            docuRef.Name = _fileName;
            docuRef.TypeId = 'File';
            docuRef.Restriction = DocuRestriction::External;
            docuRef.insert();
            archive = DocuAction::newDocuRef(docuRef);
            archive.add(docuRef, _fileName);
        }
        catch(Exception::CLRError)
        {
            //Access the last CLR Exception
            info(CLRInterop::getLastException().ToString());
            AifUtil::getClrErrorMessage();
            //See AifUtil::getClrErrorMessage for another alternative
            //how to parse the Exception object
        }

    }
}
//End

Since PO confirmation class is running server-side, docuActionArchive class->add method is changed to server-side. Refer this link in my blog: https://www.blogger.com/blogger.g?blogID=3375586050608221914#editor/target=post;postID=7858382166586064691;onPublishedMenu=editor;onClosedMenu=editor;postNum=1;src=postname

Docuref in batch (server side)

Adding attachment with transaction when running in server-side


DocuActionArchive class

Add method

if (docuRules)
    {
          // Begin
        //fileSize = WinAPI::fileSize(attachFilename);
        if(isRunningOnServer())
        {
            fileSize = WinAPIServer::fileSize(attachFilename);
        }
        else
        {
            fileSize = WinAPI::fileSize(attachFilename);
        }
        // End
         
          isFileSizeOk = Docu::validateFileSize(_docuRef.docuType() ,fileSize);
 
      }


else
        {
              // Begin
            //WinAPI::copyFile(attachFilename, docuFilename);
            if(isRunningOnServer())
            {
                WinAPIServer::copyFile(attachFilename, docuFilename);
            }
            else
            {
                WinAPI::copyFile(attachFilename, docuFilename);
            }
            //End
             
          }