web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Post and update person image with custom services in x++

(1) ShareShare
ReportReport
Posted on by 16
I am working on custom services for updates and inserting new person's images.
 
The requirement is we are integrated with a mobile app that shows the person's image and if we need to update we can update or insert a new image for the person.
 
is it possible with a custom service if yes please share the code for it.
 
or if any idea how can we achieve it.
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    Using a custom service is possible. For example, you could have a service operation accepting a party number and System.Byte[] object.
     
    Another approach is using HcmPersonImageEntity through a data management API.
  • Ghzanfar Abbas Profile Picture
    16 on at
    Thanks Martin for quick response.
     
    Can you share code examples for the custom service?
  • Suggested answer
    Ghzanfar Abbas Profile Picture
    16 on at
    Thanks Martin for quick response.
     
    Can you share code examples for the custom service?
     
    I am your response Martin.
  • Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    What do you want the example to show? Are you saying that you tried to follow my suggestion ("For example, you could have a service operation accepting a party number and System.Byte[] object") and you ran into a problem?
  • Suggested answer
    Ghzanfar Abbas Profile Picture
    16 on at
    I want you to share with me the code how to upload image through custom service because I have no idea how to code.
    Or share the article related it thanks.
  • Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    Aha, you want me to develop the whole thing for you. Sorry, I'm not going to do it. I'm willing to answer your question but not doing your work for you. I don't even have time for that.
     
    Maybe you should simply use the data entity instead of trying to implement a custom solution for the same thing, if you're unable to do it.
     
    And if you insist, either use my suggest or design a different solution, e.g. use a string parameter with the image encoded with Base64. It'll likely be easier for you than dealing with binary data directly.

    Choose the solution that suits you the best and try to implement. If you have no idea how to do it, e.g. how to use the data entity or how to create a trivial custom service, check out documentation and ask questions here if needed.

    Then start the implementation. For example, if you decided to use a custom service, create a simple service just accepting a parameter (without processing the data for now) and test that you can call it. Ask questions if you get into problems.
  • Suggested answer
    Ghzanfar Abbas Profile Picture
    16 on at
    Hi Martin,
     
    I am very grateful to you for your quick response.
    sorry for the misunderstanding I do not want to develop the whole thing for myself. I just want if you any any articles or code examples to share with me for help.
     
     
  • Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    But it's not clear what you want us to show you.
     
    Please answer: do you know how to create a custom service accepting a single string parameter?
     
    If not, you're looking for basics of custom services; you're not yet in a situation to implement anything about images. That will come later.
     
    If you know how to create a custom services, giving you examples of that would be useless for you and a waste of time for us. It would mean that you're actually struggling with something else, but it's not clear what it is unless you write it down.
  • Suggested answer
    Ghzanfar Abbas Profile Picture
    16 on at
    Yes, I know about the service and created the service class with the accepting a string parameter method for a return person image, and it's working fine with Postman.
     
    My service operation method code is
     
    public str getEmployeeImage(HcmPersonId _Id)
        {
            HcmPersonImage personImage;
            bindata bin = new bindata();
            str content;
            container image;
            select personImage where personImage.Person == HcmWorker::findByPersonnelNumber(_Id).Person;
            image = personImage.Image;
            bin.setData(image);
            content=bin.base64Encode();
            return content;
        }
     
    Now I want to upload or update the image from Postman or the mobile app
     
    here is my code for uplaod image
     
        public void uploadEmployeeImage(Bitmap _image, HcmPersonRecId _personId)
        {
            HcmPersonImage personImage;
           
            try
            {
                ttsbegin;
               
                 personImage = HcmPersonImage::findByPerson(_personId, true);
                if(!personImage)
                {
                    personImage.Person = _personId;
                    personImage.Image = _image;
                    personImage.insert();
                }
                else
                {
                    personImage.Image = _image;
                    personImage.update();
                }
                ttscommit;
            }
            catch
            {
                ttsabort;
            }
        }
     
     
    I am not accepting image parameter (value is empty) from Postman with this request
     
    I hope you understand my issue please tell me where I am making mistakes in the code.
     
     
     
     
     
  • Suggested answer
    Martin Dráb Profile Picture
    240,281 Most Valuable Professional on at
    Your export method returns the image as string (with binary data encoded to string with Base64).
     
    If you want the same approach on import, the type of the parameter must be string, not Bitmap. You'll then use something like BinData::loadFromBase64() to convert the string to binary data.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 284 Super User 2026 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 258 Most Valuable Professional

#3
Anton Venter Profile Picture

Anton Venter 228 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans