Wednesday, 5 February 2020

X++ Job to list all the elements which are not included in version control

 X++ Job to list all the elements which are not included in version control

static void listNonVersionControlled(Args _args)
{
    SysVersionControllable  controllable;
    SysModelElement         sme_root, sme;
    SysModelElementData     smeData;
    SysModelLayer           layer;   
   
    setPrefix('Not version controlled elements');
   
    while select sme_root
        order by elementType
        exists join sme
        exists join smeData
        exists join layer
         where sme.RootModelElement     == sme_root.RecId
            && sme.RecId                == smeData.ModelElement       
            && smeData.layer            == layer.RecId          
            && smeData.ModelId          == xInfo::getCurrentModelId()
            && layer.Layer              == currentAOLayer()
        {       
        controllable = SysTreeNode::newTreeNodePath(SysTreeNode::modelElement2Path(sme_root));       
       
        if (VersionControl.parmSysVersionControlSystem().allowCreate(controllable))
        {
            info(SysTreeNode::modelElement2Path(sme_root));
        }
    }
}

Powershell command to list all the elements in AX model and DB Sync

                               Powershell commands



Install-AXModel

Parameter Set: Default
Install-AXModel -File  [-Config  ] [-Conflict  ] [-CreateParents] [-Database  ] [-Details] [-NoOptimize] [-NoPrompt] [-Replace  ] [-Server  ] [-TargetLayer  ] [ 
 
PS C:\>Install-AXModel -File MyModel.axmodel -Conflict Push
 

Export-AXModel

 
Parameter Set: Default
Export-AXModel -File  -Model  [-Config  ] [-Database  ] [-Key  ] [-ManifestFile  ] [-Server  ] [  

PS C:\>Export-AXModel -model Packaging -file c:\models\PackagingSigned.axmodel -key c:\keys\mykey.snk
 
 ----------------------------------------------------------------------------------------------------
Command to list all the elements in the model in AX (Installed )
(Note: here -Model 15 is user layer model)
------------------------------------------------------------------------------------
&"C:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1"
$s = 'D-WBX-DEV06'
$d = 'Weetabix_Dev_Model'
(get-axmodel -server $s -database $d -model 15 -details).elements | format-table -property path -autosize
--------------------------------------------------------------------------------------------------------------------

Command to list all the elements in the model File (Not Installed).
-------------------------------------------------------------------------------------
(get-axmodel -server $s -database $d -file "C:\Lasernet\Lasernet Connector for Microsoft Dynamics AX2012 R3 CU13\Model\VAR\LAC_VAR_5002_17102018_110314_AX2012R3CU13.axmodel" -details).elements | format-table -property path -autosize

Ex:
$filepath = "F:\DevOpsRepository\Builds\1.0.0.316\Application\Appl\MK.axmodel"
$s= "DataBaseServerName"
$d= "AXDatabaseName"
(get-axmodel -server $s -database $d -file $filepath -details).elements | format-table -property path -autosize | Out-File -FilePath "F:\Tmp\WCC model content.txt" -NoClobber
-------------------------------------------------------------------------------------------------------------

AX DB Sync
---------------------------------------------------------------------------------------------------------
$axProcess = Start-Process -PassThru ($axClientPath + "C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\Ax32.exe") -ArgumentList ($params + " -StartupCmd=Synchronize")
if ($axProcess.WaitForExit($AXSYNCTIMEOUT) -eq $false)
{
    Throw ("Error: Synchronize did not complete within " + $AXSYNCTIMEOUT / 60000 + " minutes")
}
---------------------------------------------------------------------------------------------------------------

Export list of model elements to Excel using PowerShell

(Get-AXModel -Model 'MyModel' -Details).Elements | select path, elementtype | `
Export-Csv -NoTypeInformation -Delimiter ';' c:\mymodel.csv

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

Uninstall-AXModel

Parameter Set: Default
Uninstall-AXModel -Model [-Config ] [-Database ] [-Details] [-Layer ] [-ManifestFile ] [-NoPrompt] [-Server ] [



PS C:\>Uninstall-AXModel -Model TestModel -Details
 

SQL DB backup and Restore script


Backup DB

USE [master]
BACKUP DATABASE [DB_NAME] TO  DISK = N'F:\SQLBackup\build_AxDB.bak' WITH NOFORMAT, INIT,  NAME = N'DBNAME', SKIP, NOREWIND, NOUNLOAD, COMPRESSION,  STATS = 10
BACKUP DATABASE [AB_NAME_model] TO  DISK = N'F:\SQLBackup\build_AxDB_model.bak' WITH NOFORMAT, INIT,  NAME = N'DBNAME', SKIP, NOREWIND, NOUNLOAD, COMPRESSION,  STATS = 10

GO



Restore DBs
#USE [master]
RESTORE DATABASE [DB_NAME] FROM  DISK = N'F:\SQLBackup\build_AxDB.bak' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 5
Find clients using the DB

DECLARE @AllConnections TABLE(
    SPID INT,
    Status VARCHAR(MAX),
    LOGIN VARCHAR(MAX),
    HostName VARCHAR(MAX),
    BlkBy VARCHAR(MAX),
    DBName VARCHAR(MAX),
    Command VARCHAR(MAX),
    CPUTime INT,
    DiskIO INT,
    LastBatch VARCHAR(MAX),
    ProgramName VARCHAR(MAX),
    SPID_1 INT,
    REQUESTID INT
)
INSERT INTO @AllConnections EXEC sp_who2
SELECT * FROM @AllConnections WHERE DBName = 'DB_NAME'

To Kill
USE [master];
DECLARE @kill varchar(8000) = '';  
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';'  
FROM sys.dm_exec_sessions
WHERE database_id  = db_id('DBNAME')

EXEC(@kill);

Find Top #n tables with max size

USE [D_WBX_BUILD]
select top 30 schema_name(tab.schema_id) + '.' + tab.name as [table],
    cast(sum(spc.used_pages * 8)/1024.00 as numeric(36, 2)) as used_mb,
    cast(sum(spc.total_pages * 8)/1024.00 as numeric(36, 2)) as allocated_mb
from sys.tables tab
join sys.indexes ind
     on tab.object_id = ind.object_id
join sys.partitions part
     on ind.object_id = part.object_id and ind.index_id = part.index_id
join sys.allocation_units spc
     on part.partition_id = spc.container_id
group by schema_name(tab.schema_id) + '.' + tab.name
order by sum(spc.used_pages) desc;


Command to delete data from the table

use [DB_NAME]
--    TRUNCATE TABLE        dbo.DMFWBXASNPACKSTRUCTUREENTITY







Thursday, 19 September 2019

D365FO - Importing License File (ISV/VAR Add-on) via deployable package (LCS)

In order to deploy this license file to, we need to do the following. 

It is a two-step process 

1. Copy license file to ImportISLicense.Zip folder 
Any AOS server:

Windows Explorer > \AOSService\PackagesLocalDirectory\Bin\CustomDeployablePackage
*usually C:\AOSService\PackagesLocalDirectory\Bin\CustomDeployablePackage or on the K-drive*



In here you will find the file  ImportISVLicense.zip

Make a copy of this zip file and open it up (don't unzip, just open it). 
Then browse to the following location: ImportISVLicense.zip\AosService\Scripts\License
Copy the license .txt file into this folder and save the zip.




2. Upload to LCS packages 

LCS > Open the AX project in which you wish to apply the license to which in this case is the QA environment which means we need to open the implementation project. Then go to Asset library
Go to software deployable package > Click on the add button and fill out the info regarding the file being uploaded and select the zip file we created in the steps above


wait for a couple of minutes before the "valid" box has a checkmark. You will not be able to apply this file until the instance is marked as valid.

Once the instance has been marked as valid we need to apply it to the system.

Go to the full details page for the specific environment we need to apply this to and click on the Maintain option > Apply updates


apply+updates+menu.png (1045×401)
From this window, we need to choose the asset we just created and click on apply

After this, the system will process the request and trigger emails whenever the process starts and completes.

Whenever you open the main page you will also see the current status of the import itself as well.

Reference:

Friday, 13 September 2019

D365 F&O X++ code to copy data form one table two other table with similar fields using SysdictTable

Today we will see a code, which is useful to copy data from one table to a similar table and let's say you have many fields.



public static Common copyFromToTable(Common _commonFrom, Common _commonTo)
    {
        SysDictTable    dictTable = new SysDictTable(_commonTo.TableId);
        SysDictField    dictField;
        FieldId         fieldId = dictTable.fieldNext(0);
       
        while (fieldId)
        {
            dictField = dictTable.fieldObject(fieldId);

            if (dictField.isSql() && !dictField.isSystem())
            {
                FieldName fieldName = dictField.name();
                FieldId fieldIdFrom = fieldName2Id(_commonFrom.TableId, fieldName);

                if (fieldIdFrom)
                {
                    _commonTo.(dictField.id()) = _commonFrom.(fieldIdFrom);
                }
            }

            fieldId = dictTable.fieldNext(fieldId);
        }

        return _commonTo;
    }

Monday, 13 May 2019

D365 Disable grid field based on other field value

Disable grid field based on other field value in D365 FO


Here we will see how we can disable field in the grid based on the other field value.
1. Create a call extension for the form
2. Goto From the data source and in events copay active event
3. come to class you created in step one and past it.
4. Below is the sample code. 

[ExtensionOf(formStr(FormParameters))]
final class ParametersFormUP_Extension
{
   
    ///
    /// for UsagePrice the Group should must be disabled
    ///
    ///
    ///
    [FormDataSourceEventHandler(formDataSourceStr(FormParameters,FormDatasource), FormDataSourceEventType::Activated)]
    public static void FormDatasource_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
        FormDataSource              fds = sender.formRun().dataSource(formDataSourceStr(FormParameters,FormDatasource));
        FormDatasourceTable       dsTable = fds.cursor();
        FormRun                     fr = sender.formRun();
        //FormControl                 fc = fr.design(0).controlName("FINMeters_FINRollover");
        //FormControl                 fcMeterType = fr.design(0).controlName("FINMeters_FINMeterType");

        //fc.enabled(meterTable.FINMeterType == FINMeterType::Continuous);
       
        fds.object(fieldNum(FormDatasourceTable ,fieldForGroup)).allowEdit(!(dsTable.AgreementType == AgreementType::UsagePricing));

    }

}

Thursday, 18 April 2019

Cross reference alternative D365 FO

FindStr


Today we are going to look interesting stuff, which can be very handy for the developers. This is nothing but, FindStr windows command, which searches for the patterns of text in files.


As everyone is aware of the thing that, in D365FO all the objects i.e. Tables, forms, classes, etc are stored as files (XML's). So it makes sense that, we use can use the Windows command to find the files. 

Now we will see how we can use the FindStr command. 

1. Open command prompt (as administrator)
2. Change to Package directory (CD ) Ex: C: cd K:\AosService\PackagesLocalDirectory\XXXModel\XXXModel
3.  FindStr /S /L /I  /C:"serachText"*.xml

it will give you the result similar to cross-reference 

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...