Friday, May 31, 2024

X++ code to attach a file in D365F&O

 using Microsoft.Dynamics.ApplicationPlatform.Services.Instrumentation;

using Microsoft.DynamicsOnline.Infrastructure.Components.SharedServiceUnitStorage;

using Microsoft.Dynamics.AX.Framework.FileManagement;

internal final class RunnableClass1

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu 

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

   

    public static void main(Args _args)

    {

        boolean                     ret = false;

        str docfiletype;

        Microsoft.Dynamics.AX.Framework.FileManagement.IDocumentStorageProvider storageProvider;

        DocuRef     docuref;

        str downloadUrl;

        Filename    _Filename = 'GeneralLedger-General journal custom.xlsx';

        FilePath    _filePath = @'C:\Users\Admin41df0ec1e1\Downloads\GeneralLedger-General journal.xlsx';

        System.IO.Stream    _stream;

        _stream = File::UseFileFromURL(_filePath);

        str _contentType = System.Web.MimeMapping::GetMimeMapping(_filePath);

        DocuType fileType = DocuType::find(DocuType::typeFile());

        storageProvider = Docu::GetStorageProvider(fileType, true, curUserId());


        if(storageProvider)

        {

            str uniqueFileName = storageProvider.GenerateUniqueName(_Filename);

            str fileNameWithoutExtension = System.IO.Path::GetFileNameWithoutExtension(_filePath);

            str fileExtension = Docu::GetFileExtension(uniqueFileName);

  

            if(Docu::validateExtension(fileExtension))

            {

                guid FileId = newGuid();

                DocuValue docValue;

                docValue.Name = fileNameWithoutExtension;

                docValue.FileId = FileId;

                docValue.FileName = uniqueFileName;

                docValue.FileType = "xlsx";//fileExtension;

                docValue.OriginalFileName = _Filename;

                docValue.Type = DocuValueType::Others;

                docValue.StorageProviderId = storageProvider.ProviderId;

                DocumentLocation location = storageProvider.SaveFile(docValue.FileId, uniqueFileName, contentType, stream);

                

                if (location != null)

                {

                    if(location.NavigationUri)

                    {

                        docValue.Path = location.get_NavigationUri().ToString();

                    }


                    if(location.AccessUri)

                    {

                        docValue.AccessInformation = location.get_AccessUri().ToString();

                        //info(docValue.AccessInformation);

                    }


                    if (docValue.validateWrite())

                    {

                       

                        docValue.insert();

                        DocuUploadResult DocuUploadResult =  new DocuUploadResult(_fileName, _contentType, false, "", newGuid());

                        DocuUploadResult.fileId(FileId);

                         docuref = DocuUploadResult.createDocuRef(9615,68719508511,DocuType::typeFile());

                        if(docuref)

                        {

                            ret =  true;

                        }

                        else

                        {

                            ret =  false;

                        }

                    }        

                }

             }

        }

    }


}

Thursday, May 23, 2024

Cannot stop DynamicsAxBatch service on computer Dynamics 365 for finance and operations

 


The message already shows the service name. ” DynamicsAXBatch” You can copy it from Service detail dialog.

So Open CMD with run as administrator and run the following command and get  pid

sc queryex DynamicsAxBatch


Now I have IP.

And kill the Process Id 

taskkill /f /pid 11524  

Now I start the service again.

Project is successfully complied             





Cursor moves to top when refreshing list page grid in D365F&O

    My requirement is to be the cursor on the same record when a button is clicked, but the cursor is moving according to the formdatasource setposition property, but it should be on the same record.

            FormDataSource              inventTestGroup_ds = sender.formRun().dataSource();

           int position = inventTestGroup_ds.getPosition();

            inventTestGroup_ds.refresh();

            inventTestGroup_ds.reread();

            inventTestGroup_ds.research(true);

            inventTestGroup_ds.setPosition(position);