Monday 30 September 2019

Get last 2 digits of field on to listpage

1. Create computed column method. create new field and assigned method to that. drag and drop the field on to listpage.


private static str getLastTwoCharOfCode()
        {
            #define.ViewName(CITProductCategoryView)
            #define.DataSourceName("EcoResCategory")
            #define.FieldSubsegmentId("Code")
            const str datasourceName = 'EcoResCategory';
            const str CodeField = 'Code';

            // Instantiate a DictView object for the view
            DictView viewView1 = new DictView(tableNum(CITProductCategoryView));

            str Code = viewView1.computedColumnString
                    (#DataSourceName,
                    #FieldSubsegmentId,
            FieldNameGenerationMode::FieldList,
                true);
            // create the SQL code snippet that computes the column
            str ret = "Right("+ Code+ ",2)";
            return ret;
    }

CSV to Azure File Storage


using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.File;
using Microsoft.WindowsAzure.Storage.StorageException;
#File
class WriteCSVFileInAzureFileStorage
{
    Dynamics.AX.Application.Exception exception;



    public static void main(Args _args)
    {
        CommaStreamIo io = CommaStreamIo::constructForWrite();
        str     fileName = 'Cust_DE.csv',
       fileContent;
        CustTable   custTable;

        // Write header
        io.writeExp(['Customer', 'Account number', 'Currency', 'DataAreaId']);

        // Write line
        while select custTable
     where custTable.DataAreaId == 'USMF'
        {
            io.writeExp([custTable.name(),
       custTable.AccountNum,
       custTable.Currency,
       custTable.DataAreaId]);
        }

        // Set stream
        System.IO.Stream stream = io.getStream();
        stream.Position = 0;

        // Set stream reader
        System.IO.StreamReader sReader = new System.IO.StreamReader(stream);

        // Set file contentn string
        fileContent = sReader.ReadToEnd();

        //// Save file
        //File::SendStringAsFileToUser(fileContent, fileName);
        Dynamics.AX.Application.Exception exception;
        infolog.add(exception::Info, "Azure Storage File Sample");


        WriteCSVFileInAzureFileStorage writeCSVFileInAzureFileStorage = new WriteCSVFileInAzureFileStorage();
        WriteCSVFileInAzureFileStorage::BasicAzureFileOperations(fileContent,fileName);

    }

    private static void BasicAzureFileOperations(str _fileContent,str _fileName)
    {
        //const str DemoShare = "democsvfileshare";
        const str DemoShare = "agreementfileshare";
        //const str DemoDirectory = "DemocsvFileDirectory";
        const str DemoDirectory = "AgreementcsvFileDirectory";
        //const str DemoFile = "demofile";
       // const str ImageToUpload = @'C:\Users\Usere4627ee6be0\Desktop\VS error.PNG'; //"HelloWorld.png";
        str FileContents = _fileContent;
        str fileName = _fileName;

        Dynamics.AX.Application.Exception exception;
        StorageException storageException = new Microsoft.WindowsAzure.Storage.StorageException();
       
        // Retrieve storage account information

        Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials('siyedev813pu23e0d5d398f4', 'k03yWIis7PV3yIIUNxXKseUQZ7GSQMW3Ch0Ri2vAGmWVbov/dcj/7mzjpbAYrwA46LSuvKOWZKyBpA60B+zXpA==');

        Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);

        // Create a file client for interacting with the file service.

        CloudFileClient fileClient = storageAccount.CreateCloudFileClient();

        // Create a share for organizing files and directories within the storage account.

        CloudFileShare share = fileClient.GetShareReference(DemoShare);
           
        try
        {
            share.CreateIfNotExistsAsync();
        }
        catch (storageException)
        {
            infolog.add(exception::Error, "Unable to connect to Azure File Storage");
            throw exception::Error;
        }

        // Get a reference to the root directory of the share.

        CloudFileDirectory root = share.GetRootDirectoryReference();

        // Create a directory under the root directory

        CloudFileDirectory dir = root.GetDirectoryReference(DemoDirectory);
        dir.CreateIfNotExistsAsync();

        // Creating a new file in the directory created above and writing contents to the file
        // Also delete if exists

        CloudFile file = dir.GetFileReference(fileName);
        file.DeleteIfExistsAsync();
        file.UploadTextAsync(FileContents);

        // Uploading a local file to the directory created above

        //CloudFile file = dir.GetFileReference(ImageToUpload);
        //file.UploadFromFileAsync(ImageToUpload, System.IO.FileMode::Open);
    }

}

Friday 20 September 2019

Filter the listpage Data source


public void initializeQuery(Query _query)
{
............................

....
else if (this.getListPageType() == PurchTableListPage::NkwWorkerDimensionView)
    {
        qbds = _query.dataSourceTable(tableNum(PurchTable));
        qbds.clearDynalinks();
        qbds = _query.dataSourceTable(tableNum(PurchTable)).addDataSource(tableNum(PurchLine));
        //qbds.addSortField(fieldnum(PurchLine, PurchId));
        //qbds.addOrderByField(fieldnum(PurchLine, PurchId));
        //qbds.orderMode(OrderMode::GroupBy);
        qbds.firstOnly(true);
        qbds.relations(true);
        qbds.fetchMode(0);
        //qbds.joinMode(JoinMode::ExistsJoin);
        qbds.addRange(fieldNum(PurchLine,DefaultDimension)).value(queryValue(HcmWorker::find(DirPersonUser::currentWorker()).getDefaultDimension()));
        qbds.addRange(fieldNum(PurchLine,Isdeleted)).value(queryValue(NoYes::No));

    }