Showing posts with label Image. Show all posts
Showing posts with label Image. Show all posts

Saturday, July 16, 2022

Convert Image to Base64 string in D365FO

 Convert Image to Base64 string in D365FO.

    HcmWorker           HcmWorker;
    HcmPersonImage      HcmPersonImage;
    ExecutePermission   perm;
    container           imgObj;
    BinData             bd;
    Notes               result;

    new InteropPermission(InteropKind::ClrInterop).assert();
    perm = new ExecutePermission();
    perm.assert();

    HcmWorker       = HcmWorker::findByPersonnelNumber('employeeId');
    HcmPersonImage  = HcmPersonImage::findByPerson(HcmWorker.Person);
    
    imgObj = HcmPersonImage.Image;
    bd = new BinData();
    bd.setData(imgObj);
    
    result = bd.base64Encode();
    //ssPermission::revertAssert();



Keep Daxing!!




Tuesday, November 16, 2021

Add symbol icons to the Grid in Dynamics 365FO

 

    We see how to add symbol icons to the grid in Dynamics 365FO. I have to add icons to the records based on qty. 


For this, 

1. I have created a display method on my table.     

    [SysClientCacheDataMethod(true)]
    public display container logo()
    {
        ImageReference          imageReference;
        container               image;
        
        
        //imageReference = ImageReference::constructForSymbol(
				this.QtyAvailable mod 2 ? 'GreenCheck' : 'RedX');
				
        str name = this.QtyAvailable mod 2 ? 'GreenCheck' : (
				this.QtyAvailable mod 3 ? 'YellowTriangle': 'RedX');
        imageReference = ImageReference::constructForSymbol(name);

        if (imageReference)
        {
            image = imageReference.pack();
        }

        return image;
    }

2. Created new Form image control in the form grid and set up the properties for that control.





Symbols:
  • GreenCheck
  • YellowTriangle
  • RedX
  • GreenCircle
  • RedDiamond
  • BlueSquare
  • RedSquare
  • GreenSquare
  • OrangeSquare
  • GreenSquare
  • YellowSquare
  • TemporaryUser
  • EditEvent
  • YellowExclamationPoint
We can use the above symbols as per our requirements.

Reference: https://www.avantiico.com/adding-symbol-font-icons-to-a-grid-in-dynamics-365-for-finance-and-operations-enterprise-edition/

Keep Daxing!!

Friday, October 1, 2021

upload Image File to D365FO using X++

 I got a requirement like I have to add signature image to company and I have to populate in my custom report.

Steps:

1.Added "container field" in table.

2.Added New fast tab, buttons and Image control in form as shown below.



3. Written the code in below class. By Event handler methods I written the code.

    public class OMLegalEntityEventHandler { // Change button clicked method { FormDataSource companyInfo_ds = sender.formRun().dataSource(1) as FormDataSource; CompanyInfo companyInfo = companyInfo_ds.cursor() as CompanyInfo; str imageFilePathName; ; imageFilePathName = OMLegalEntityEventHandler::uploadImageFile(); if (imageFilePathName) { ttsbegin; companyInfo.selectForUpdate(true); companyInfo.CompanySignature = ImageReference::GetPackedBinaryData(imageFilePathName); companyInfo.update(); ttscommit; } companyInfo_ds.research(true); } //Remove button clicked method { FormDataSource companyInfo_ds = sender.formRun().dataSource(1) as FormDataSource; CompanyInfo companyInfo = companyInfo_ds.cursor() as CompanyInfo; ; ttsbegin; companyInfo.selectForUpdate(true); companyInfo.CompanySignature = conNull(); companyInfo.update(); ttscommit; companyInfo_ds.research(true); } // Data source activate method { CompanyInfo companyInfo = sender.cursor() as CompanyInfo; FormWindowControl logoImage = sender.formRun().design().controlName(formControlStr(OMLegalEntity, DashboardSignatureImage)) as FormWindowControl; Image _image; ; if (companyInfo.CompanySignature) { _image = new Image(); _image.setData(companyInfo.CompanySignature); logoImage.image(_image); } else { logoImage.image(null); } } // File upload from this method public static str uploadImageFile() { FormRun visualForm; FileUpload fileUploadControl; str imageFilePathName; ; visualForm = classFactory::formRunClassOnClient(new Args(formstr(SysGetFileFromUser))); visualForm.init(); visualForm.design().caption("@ApplicationPlatform:GetFileImageCaption"); fileUploadControl = visualForm.design().controlName('FileUpload1'); visualForm.run(); visualForm.wait(); FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult(); if (fileUploadResult != null && fileUploadResult.getUploadStatus()) { imageFilePathName = fileUploadResult.getDownloadUrl(); } return imageFilePathName; } }

Keep daxing!!