Tuesday, August 20, 2019

SQL server error while opening visual studio. - solution

Issue: SQL server error while opening visual studio.

Error: A network-related or instance-specific error occurred when establishing a connection to SQL server. The server was not found or was not accessible. ... (provider: Named pipes provider, error: 40 -  Could not open a connection to SQL server)



Resolution: Make sure the SQL server services are running in the machine. Re-open visual studio after service has been started.

Sunday, August 11, 2019

Adding new print management report node in D365 - code sample

public static class PrintMgmtDelegates_Extension
{
 
    /// <summary>
    ///
    /// </summary>
    /// <param name="_nodeType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDelegates), delegateStr(PrintMgmtDelegates, constructPrintMgmtNodeDelegate))]
    public static void PrintMgmtDelegates_constructPrintMgmtNodeDelegate(PrintMgmtNodeType _nodeType, EventHandlerResult _result)
    {
        switch (_nodeType)
        {
            case printmgmtNOdeTYpe::Custom:

                PrintMgmtNode_Custom    printMgmtNode_Custom = new PrintMgmtNode_Custom();
                _result.result(printMgmtNode_Custom);

                break;
        }
    }

}



--------------------------------------------

[ExtensionOf(classStr(PrintMgmtHierarchy_Sales))]
final class PrintMgmtHierarchy_Sales_Extension
{
    protected List getNodesImplementation()
    {
        //List supportedNodes = new List(Types::Enum);
        var supportedNodes = next getNodesImplementation();
        supportedNodes.addEnd(PrintMgmtNodeType::Custom);
        return supportedNodes;
    }

    protected PrintMgmtNodeInstance getParentImplementation(PrintMgmtNodeInstance _nodeInstance, PrintMgmtDocumentType _docType)
    {
        PrintMgmtNodeInstance result;
        result  = next getParentImplementation(_nodeInstance, _docType);
        return result;
    }

}
----------------------------------------------

class PrintMgmtNode_Custom extends PrintMgmtNode
{
    protected str getDisplayCaptionImplementation(Common _tableBuffer)
    {
        return(strfmt("@SYS108944", _tableBuffer.caption()));
    }

    public List getDocumentTypes()
    {
        List    docTypes;

        docTypes = new List(Types::Enum);

        if (isConfigurationkeyEnabled(configurationkeynum(LogisticsBasic)))
        {
            docTypes.addEnd(PrintMgmtDocumentType::Custom);
        }

        return docTypes;
    }

    public int getIconImageResNum()
    {
        #resAppl

        return #ImagePrintManagementTrans;
    }

    public PrintMgmtNodeType getNodeType()
    {
        return PrintMgmtNodeType::Custom;
    }

    public RefTableId getReferencedTableId()
    {
        return tablenum(CustomTable);
    }

}

----------------------------------------

class PrintMgmtNode_Sales_Custom
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(PrintMgmtNode_Sales), methodStr(PrintMgmtNode_Sales, getDocumentTypes))]
    public static void PrintMgmtNode_Sales_Post_getDocumentTypes(XppPrePostArgs args)
    {
        List docTypes;
        docTypes    = new List(Types::Enum);
        docTypes    = Args.getReturnValue();
        docTypes.addEnd(PrintMgmtDocumentType::Custom);

        Args.setReturnValue(docTypes);
    }

}

----------------------


class PrintMgtDocTypeHandlersExt
{
 

    /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        switch (_docType)
        {
            case PrintMgmtDocumentType::Custom:
                _result.result(ssrsReportStr(SalesConfirmExt, Report));
                break;
        }
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="_docType"></param>
    /// <param name="_result"></param>
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getQueryTableIdDelegate))]
    public static void PrintMgmtDocType_getQueryTableIdDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {
        TableId     tableId;

        switch(_docType)
        {
            case PrintMgmtDocumentType::Custom:
                tableId = tableNum(CustomTable);
                _result.result(tableId);
                break;
        }
    }

}
---------------

class SalesConfirmControllerExt extends SalesConfirmController
{
    public static SalesConfirmControllerExt construct()
    {
        return new SalesConfirmControllerExt();
    }

    public static void main(Args _args)
    {
        SrsReportRunController      formLetterController = SalesConfirmControllerExt::construct();
        SalesConfirmControllerExt   controller = formLetterController;controller.initArgs(_args, ssrsReportStr(SalesConfirmExt, Report));
     
        if (classIdGet(_args.caller()) == classNum(SalesConfirmJournalPrint))
        {
            formLetterController.renderingCompleted += eventhandler(SalesConfirmJournalPrint::renderingCompleted);
        }
     
        formLetterController.startOperation();
    }

}

----------------------

Thursday, August 1, 2019

More than one form was opened at once for lookup control. - solution


Issue: More than one form was opened at once for lookup control.

Resolution: The form control lookup can be extended to get desired lookup using below code:

[FormControlEventHandler(formControlStr(EcoResProductParameters, EcoResProductParameters_ProductEntityAttributeMasterCompanyId), FormControlEventType::Lookup)]
    public static void EcoResProductParameters_ProductEntityAttributeMasterCompanyId_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormControlCancelableSuperEventArgs fccse = e as FormControlCancelableSuperEventArgs;
        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(CompanyInfo), sender);
        Query query = new Query();
        query.addDataSource(tableNum(CompanyInfo));
        sysTableLookup.addLookupfield(fieldNum(CompanyInfo, DataArea));
        sysTableLookup.addLookupfield(fieldNum(CompanyInfo, TSTGlobalNumber));
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
        fccse.CancelSuperCall();
    }

Fields are not visible in the form after adding field group in D365. - solution

Issue: Fields are not visible in the form after adding field group.

Resolution:  It might be due to "Data group" property. Try to clear the "Data group" property from the grid/group control, so that fields are visible in the form.