Thursday, December 31, 2020

How to Delete Models in Dynamics 365 F&O

1. Stop the AOS web services (Go to IIS and look for "AOS services" and stop it)

2. Stop Microsoft Dynamics 365 Unified Operations: Batch Management Service [type services.msc into run and search for it]

3. Now go to C:\AOSService\PackagesLocalDirectory

4. Delete your model

5. Now start the AOS web services and Batch Management services

6. Now refresh models

7. Synchronize the database


Monday, December 28, 2020

Error in UAT/Production "Cannot create a record in SysXppAssembly (SysXppAssembly)"

Create a  new job 


static void TTC_AY_SysXppAssembly(Args _args)

{

    SysXppAssembly  SysXppAssembly;

    delete_from SysXppAssembly;

}


Now Run it.


Now run a Full CIL

Tada! Error resolved

Saturday, December 26, 2020

Dynamics 365 F&O Import data from CSV

In this example We will be importing name and id from a csv file in a table.


class TTC_AY_ImportFile

{

    public static void main(Args _args)

    {

        AsciiStreamIo                       file;

        FileUploadTemporaryStorageResult    fileUpload;

        TTC_WorkerTable                     workerTable;

        Counter                             counter = 0;

        str                                 Name;

        #OCCRetryCount


        try

        {

            fileUpload  = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

            file        = AsciiStreamIo::constructForRead(fileUpload.openResult());

            if (file)

            {

                if (file.status())

                {

                    throw error("Unknown problem while importing file");

                }

                file.inFieldDelimiter(';'); //separator

                file.inRecordDelimiter('\r\n');

            }


            //Read a CSV File

            container rec;

            ttsbegin;

            while (!file.status())

            {

                counter++;

                rec = file.read();

                if (conLen(rec))

                {

                    Name = conPeek(rec, 2);

                    workerTable = TTC_WorkerTable::find(Name);

                    

                    if(!workerTable.RecId)

                    {

                        workerTable.clear();

                        workerTable.Id    = conPeek(rec, 1);

                        workerTable.Name  = Name;

                        workerTable.insert();

                    }

                }

            }

            ttscommit;

            info("Operation complete.");

        }

        catch (Exception::Deadlock)

        {

            retry;

        }

        catch (Exception::UpdateConflict)

        {

            if (appl.ttsLevel() == 0)

            {

                if (xSession::currentRetryCount() >= #RetryNum)

                {

                    throw Exception::UpdateConflictNotRecovered;

                }

                else

                {

                    retry;

                }

            }

            else

            {

                throw Exception::UpdateConflict;

            }

        }

    }

}


Sunday, December 20, 2020

Dynamics 365 Chain of commands

In this example We will be showing name and personnel number of worker at Worker creation and automatically deleting the worker


[ExtensionOf(tableStr(HcmWorker))]

final class TTC_HcmWorker_Extension

{

    public void insert()

    {

        next insert();

        Info(strFmt("%1",this.PersonnelNumber));

        Info(strFmt("%1",this.name()));

        this.delete();

    }

}

Export data to CSV file - JOB AX 2012

static void JobExportWorker(Args _args)

{

    HcmWorker                               hcmWorker;

    CommaTextIo                           file;

    container                                   line;

    #define.filename(@'C:\Worker.csv')

    #File

    file = new CommaTextIo(#filename, #io_write);

    if (!file || file.status() != IO_Status::Ok)

    {

        throw error("File cannot be opened.");

    }

    file.outRecordDelimiter('\r\n');

    file.outFieldDelimiter('\t');


    while select hcmWorker

    {

            line = [hcmWorker.personnelnumber,hcmWorker.Name()];

            file.writeExp(line);

    }

    info(strFmt("File %1 created.", #filename));

}