POST data save into variable

0
while I'm posting the name of the user I'm receiving the ID . How can i use this id or save this id into a variable.
asked
4 answers
1

Assuming you are using the Call REST Activity. You can set up how to handle the response

image.png

You could store it as a string variable and filter out the id, but it would be better to use an import mapping.

Take a look at this section of the Import/Export Learning path to find out more about working with a (JSON) response. I would recommend you to walk through the entire path to get a good overview of the integration structure. And it will explain how to interpret the things you see below in detail.

 

UPDATE:

If you paste your response into a JSON structure, you will get this

image.png

The mapping you can create from this looks like this

image.png

And the entities like this

image.png

So in the microflow you use to post and get your id's, you will have the following steps

 

image.png

1) Create the POST call, response should be based on the mapping and you can store the variable in the Root.

2) Retrieve the IDs object via association (because it is all non persistable)

3) Retrieve the List of values via association (because it is all non persistable)

4) Count the number of values to make sure about the result

5) create decisions for alternate flows in case of no or multiple responses

6) use the Head List Operation to get the first record from the Values list.

 

Now you have the 1 object with the ID as a value, that you can then use in logic to store in an attribute or the selected entity/object.

 

Make sure to use an error flow as well to allow custom error handling.

answered
0

image.png

I want to post that Post ID into this $root/salesperson id which i am not able to do by using import mapping and string variable

answered
0
  1. Create a Microflow:

    • In Mendix Modeler, create a new Microflow or use an existing one.
  2. Add Input Parameter:

    • Add an input parameter to the Microflow to receive the name of the user. Click on the Microflow canvas, go to the "Properties" tab, and add a new parameter with the appropriate data type (e.g., String for the user name).
  3. Retrieve the User by Name:

    • Use the "Retrieve" action in the Microflow to fetch the user entity based on the provided name. You can use the User entity or any other entity that stores user information.
  4. Get the User ID:

    • Once you have retrieved the user entity, use the "Get" action to extract the ID attribute from the user entity.
  5. Save ID to a Variable:

    • Add a variable in the Microflow to store the user ID. Assign the retrieved user ID to this variable.
  6. Return the User ID:

    • Configure the Microflow to return the user ID as the output.
  7. Call the Microflow:

    • In the part of your application or wherever you are posting the name and receiving the ID, call this Microflow passing the name as a parameter.

Adapt this example based on your data model and requirements. This is a basic structure to help you understand the concept. Make sure to handle potential scenarios where the user with the given name may not exist or where multiple users have the same name, depending on your application's logic.

 

** You can reach out to me if you get stuck in any step.

answered
0

This is my domain model were root is post api. In usernameID I'm passing the currect user name and through post api username is converted into id.

I want that id should be equal to salesperson_master_id in root.

image.pngimage.png

 

this the post of root

 

image.png

 

image.png

answered