Thursday, June 27, 2019

Document Routing Agent D365FO

Document Routing Agent is an application which enables network printing scenarios in Dynamics 365 for Finance and Operations. It basically manages the spooling of documents to network printer devices.
Install/Configure Document Routing Agent:
Navigate for network printers page 
-> Organization administration > Setup > Network printers
       -> Options tab, in the Application group, 
       -> click -> Download document routing agent installer.
-> Once downloaded an executable file double click to install it on system.
-> Close all browser
-> Run -> Document Routing Agent
      -> Click -> Setting 
                  -> Enter Application Id, AAD tenant, D365 URL
-> Sign In Document Routing Agent using Credentials
-> On Document Routing Agent
      -> Click -> Printers
      -> Navigate to Network Printer
      -> Edit and Make Active to YES for necessary printers

Note:
'Microsoft Dynamics 365 Document Routing Service' service should run under "Domain admin user"

Friday, June 21, 2019

Export Text file and send to User in D365

      str     fileName = test.txt;
str _outputStr = "Test: san: son: Test001";
        TextStreamIo textStreamIo;
       
        textStreamIo = TextStreamIo::constructForWrite();

        if (textStreamIo)
        {
            textStreamIo.write(_outputStr);
            textStreamIo.finalize();
            File::SendFileToUser(textStreamIo.getStream(), fileName);
        }
        else
        {
            warning(strfmt("@SYS65356",fileName));
        }

Wednesday, June 12, 2019

Import New user using SQL in Azure cloud DEV VM in D365 FO



INSERT INTO USERINFO(Id, Name, ENABLE, COMPANY,SID,NETWORKDOMAIN, NETWORKALIAS, ENABLEDONCE,LANGUAGE,
 HELPLANGUAGE, PREFERREDTIMEZONE, ACCOUNTTYPE,DEFAULTPARTITION)
VALUES ('<UserId>','<Name>',1,'<Default company login>','<SID>',
'https://sts.windows.net/',
'<Email Id>',1,'en-us','en-us',<Timezone>,2,1);

Insert into SECURITYUSERROLE (USER_, SECURITYROLE, ASSIGNMENTSTATUS, ASSIGNMENTMODE)
values ('<UserId>','199',1,1),
 ('<UserId>','217',1,1);

Step:

Method 1:
1. Right click on AOT -> Refresh
2. Full DB sync
3. iisreset

Method 2: (Method 1 is not working)
1. Right click on AOT -> Refresh
2. Build App Suite model with DB sync
3. iisreset

Method 3: (if Method 1 & 2 is not working)
1. Right click on AOT -> Refresh
2. Full Build All model with DB sync
3. iisreset




Tuesday, June 11, 2019

OverRide Print Mgmt Email setting for To/CC setting in D365 FO


final class SAN_PrintMgmtDelegatesHandler
{
    /// <summary>
    /// Delegate handler for the getEmailAddressDelegate method of the <c>PrintMgmtDocType</c> class.
    /// </summary>
    /// <param name = "_docType"><c>PrintMgmtDocumentType</c> enumeration value.</param>
    /// <param name = "_purpose"><c>SrsPrintDestinationToken</c> object.</param>
    /// <param name = "_jour"><c>Common</c> object containing journal record.</param>
    /// <param name = "_printMgmtPrintDestinationTokens"><c>PrintMgmtPrintDestinationTokens</c> object.</param>
    /// <param name = "_result">The <c>EventHandlerResult</c> object.</param>
    [SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getEmailAddressDelegate))]
    public static void getEmailAddressDelegateHandler(PrintMgmtDocumentType _docType, SrsPrintDestinationToken _purpose, Common _jour, PrintMgmtPrintDestinationTokens _printMgmtPrintDestinationTokens, EventHandlerResult _result)
    {
        if(_docType == PrintMgmtDocumentType::PurchaseOrderRequisition)
        {
            _result.result(""); //TODO ur Logic
        }
        else
        {
            _result.result(SAN_PrintMgmtDelegatesHandler::getEmailAddress(_docType, _purpose, _jour, _printMgmtPrintDestinationTokens));
        }
    }

    private static str getEmailAddress(PrintMgmtDocumentType _docType, SrsPrintDestinationToken _purpose, Common _jour, PrintMgmtPrintDestinationTokens _printMgmtPrintDestinationTokens)
    {
        PrintMgmtPrintDestinationPartyType partyType;
        CustVendAC ac;
        DirPartyRecId partyRecId;
        CompanyId acCompany;

        if (!_printMgmtPrintDestinationTokens)
        {
            throw error(strFmt("@SYS318601", @"_printMgmtPrintDestinationTokens"));
        }

        if (_jour.TableId == tableNum(CustQuotationJour) && _jour.(fieldNum(CustQuotationJour, BusRelAccount)))
        {
            partyRecId = smmBusRelTable::find(_jour.(fieldNum(CustQuotationJour, BusRelAccount))).Party;
        }
        else
        {
            [partyType, ac] = SAN_PrintMgmtDelegatesHandler::getDestinationPartyTypeAndId(_docType, _jour);

            if (SAN_PrintMgmtDelegatesHandler::hasDataAreaIdField(_jour))
            {
                partyRecId = SAN_PrintMgmtDelegatesHandler::getPartyRecId(partyType, ac, _jour.DataAreaId);
            }
            else
            {
                partyRecId = SAN_PrintMgmtDelegatesHandler::getPartyRecId(partyType, ac);
            }
        }
       
        return _printMgmtPrintDestinationTokens.getEmailAddressForParty(partyType, partyRecId, _purpose);
    }

    private static boolean hasDataAreaIdField(Common _common)
    {
        boolean hasDataAreaId;

        if (_common)
        {
            DictTable dictTable = new DictTable(_common.TableId);
            hasDataAreaId = dictTable && dictTable.dataPrCompany();
        }

        return hasDataAreaId;
    }

    private static container getDestinationPartyTypeAndId(PrintMgmtDocumentType _docType, Common _jour)
    {
        // NOTE: mappings from _jour to a specific table are found in the CustVendAccountMap
        // The table mapped is the same table referenced in method getQueryTableId()
        CustVendAC getAccount(Common _common)
        {
            CustVendAccountMap accountMap = _common;

            return accountMap.Account;
        }

        container fiscalDocument_BRParty(FiscalDocument_BR _fiscalDocument_BR)
        {
            switch (_fiscalDocument_BR.FiscalDocumentAccountType)
            {
                case CustVendType_BR::Customer:
                    return [PrintMgmtPrintDestinationPartyType::Customer, _fiscalDocument_BR.FiscalDocumentAccountNum];
                case CustVendType_BR::Vendor:
                    return [PrintMgmtPrintDestinationPartyType::Vendor, _fiscalDocument_BR.FiscalDocumentAccountNum];
                default:
                    return [PrintMgmtPrintDestinationPartyType::Unknown, _fiscalDocument_BR.FiscalDocumentAccountNum];
            }
        }

        container bankChequeTable_ACParty(BankChequeTable _bankChequeTable)
        {
            switch (_bankChequeTable.RecipientType)
            {
                case BankChequeRecipientType::Cust:
                    return [PrintMgmtPrintDestinationPartyType::Customer, _bankChequeTable.RecipientAccountNum];
                case BankChequeRecipientType::Vend:
                    return [PrintMgmtPrintDestinationPartyType::Vendor, _bankChequeTable.RecipientAccountNum];
                default:
                    return [PrintMgmtPrintDestinationPartyType::Unknown, _bankChequeTable.RecipientAccountNum];
            }
        }

        switch (_docType)
        {
            case PrintMgmtDocumentType::ComplementaryInvoice_BR:
            case PrintMgmtDocumentType::TransferOrderFiscalDoc_BR:
                return fiscalDocument_BRParty(_jour);

            case PrintMgmtDocumentType::BankCheque:
                return bankChequeTable_ACParty(_jour);

            default:
                switch (SAN_PrintMgmtDelegatesHandler::getPartyType(_docType, _jour))
                {
                    case PrintMgmtPrintDestinationPartyType::Customer:
                        return [PrintMgmtPrintDestinationPartyType::Customer, getAccount(_jour)];
                    case PrintMgmtPrintDestinationPartyType::Vendor:
                        return [PrintMgmtPrintDestinationPartyType::Vendor, getAccount(_jour)];
                }
        }

        return conNull();
    }

    private static DirPartyRecId getPartyRecId(PrintMgmtPrintDestinationPartyType _partyType, CustVendAC _ac, CompanyId _acCompany = curExt())
    {
        DirPartyRecId getCustParty(CustAccount _account)
        {
            CustTable custTable;

            changecompany (_acCompany)
            {
                select Party from custTable where custTable.AccountNum == _account;
            }

            return custTable.Party;
        }

        DirPartyRecId getVendParty(VendAccount _account)
        {
            VendTable vendTable;

            changecompany(_acCompany)
            {
                select Party from vendTable where vendTable.AccountNum == _account;
            }

            return vendTable.Party;
        }

        switch (_partyType)
        {
            case PrintMgmtPrintDestinationPartyType::Customer:
                return getCustParty(_ac);
            case PrintMgmtPrintDestinationPartyType::Vendor:
                return getVendParty(_ac);
            case PrintMgmtPrintDestinationPartyType::Unknown:
                return 0;
        }

        throw error(Error::wrongUseOfFunction(funcName()));
    }

    private static PrintMgmtPrintDestinationPartyType getPartyType(PrintMgmtDocumentType _docType, Common _jour = null)
    {
        PrintMgmtPrintDestinationPartyType fiscalDocument_BRParty(FiscalDocument_BR _fiscalDocument_BR)
        {
            switch (_fiscalDocument_BR.FiscalDocumentAccountType)
            {
                case CustVendType_BR::Customer:
                    return PrintMgmtPrintDestinationPartyType::Customer;
                case CustVendType_BR::Vendor:
                    return PrintMgmtPrintDestinationPartyType::Vendor;
            }

            return PrintMgmtPrintDestinationPartyType::Unknown;
        }

        PrintMgmtPrintDestinationPartyType bankChequeTable_ACParty(BankChequeTable _bankChequeTable)
        {
            switch (_bankChequeTable.RecipientType)
            {
                case BankChequeRecipientType::Cust:
                    return PrintMgmtPrintDestinationPartyType::Customer;
                case BankChequeRecipientType::Vend:
                    return PrintMgmtPrintDestinationPartyType::Vendor;
            }

            return PrintMgmtPrintDestinationPartyType::Unknown;
        }

        switch (_docType)
        {
            case PrintMgmtDocumentType::SIProjInvoice:
           case PrintMgmtDocumentType::SIProjInvoiceWithBR:
            case PrintMgmtDocumentType::SIManagedProjInvoice:
            case PrintMgmtDocumentType::ProjCustRetentionReleaseInvoice:
            case PrintMgmtDocumentType::ProjectInvoice:
            case PrintMgmtDocumentType::SalesOrderInvoice:
            case PrintMgmtDocumentType::SalesFreeTextInvoice:
            case PrintMgmtDocumentType::InventPickList:
            case PrintMgmtDocumentType::SalesOrderPackingSlip:
            case PrintMgmtDocumentType::SalesOrderConfirmation:
            case PrintMgmtDocumentType::Confirmation:
            case PrintMgmtDocumentType::ProjectQuotation:
            case PrintMgmtDocumentType::Quotation:
            case PrintMgmtDocumentType::SalesOrderInvoice4Paym_RU:
            case PrintMgmtDocumentType::SalesFreeTextInvoice4Paym_RU:
            case PrintMgmtDocumentType::WMSBillOfLading_RU:
            case PrintMgmtDocumentType::WMSBilOfLadingTranspDocument_RU:
            case PrintMgmtDocumentType::CustAccountStatement:
            case PrintMgmtDocumentType::CustCollectionLetter:
            case PrintMgmtDocumentType::CustInterestNote:
            case PrintMgmtDocumentType::SalesAgreementConfirmation:
            case PrintMgmtDocumentType::SalesAdvanceInvoice:
            case PrintMgmtDocumentType::CustPaymAdvice:
                return PrintMgmtPrintDestinationPartyType::Customer;

            case PrintMgmtDocumentType::PurchaseOrderInvoice:
            case PrintMgmtDocumentType::PurchaseOrderPackingSlip:
            case PrintMgmtDocumentType::PurchaseOrderReceiptsList:
            case PrintMgmtDocumentType::PurchaseOrderRequisition:
            case PrintMgmtDocumentType::PurchRFQ:
            case PrintMgmtDocumentType::PurchRFQAccept:
            case PrintMgmtDocumentType::PurchRFQReject:
            case PrintMgmtDocumentType::PurchRFQReturn:
            case PrintMgmtDocumentType::PurchOrderInvoice4Paym_RU:
            case PrintMgmtDocumentType::PurchAgreementConfirmation:
            case PrintMgmtDocumentType::PurchaseAdvanceInvoice:
            case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest:
            case PrintMgmtDocumentType::VendPaymAdvice:
                return PrintMgmtPrintDestinationPartyType::Vendor;

            case PrintMgmtDocumentType::ComplementaryInvoice_BR:
            case PrintMgmtDocumentType::TransferOrderFiscalDoc_BR:
                return fiscalDocument_BRParty(_jour);

           case PrintMgmtDocumentType::BankCheque:
                return bankChequeTable_ACParty(_jour);
        }

        return PrintMgmtPrintDestinationPartyType::Unknown;
    }

}





Convert Call stack to readable format in D365FO X++

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