web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    237,679 Most Valuable Professional on at
    Post and update person image with custom services in x++
    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
    Post and update person image with custom services in x++
    Thanks Martin for quick response.
     
    Can you share code examples for the custom service?
  • Suggested answer
    Ghzanfar Abbas Profile Picture
    16 on at
    Post and update person image with custom services in x++
    Thanks Martin for quick response.
     
    Can you share code examples for the custom service?
     
    I am your response Martin.
  • Martin Dráb Profile Picture
    237,679 Most Valuable Professional on at
    Post and update person image with custom services in x++
    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
    Post and update person image with custom services in x++
    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
    237,679 Most Valuable Professional on at
    Post and update person image with custom services in x++
    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
    Post and update person image with custom services in x++
    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
    237,679 Most Valuable Professional on at
    Post and update person image with custom services in x++
    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
    Post and update person image with custom services in x++
    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
    237,679 Most Valuable Professional on at
    Post and update person image with custom services in x++
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans