# Using a routine in a map

Use a Java function to call a routine that generates a random string.

## Before you begin

You have created a map with an input and output structure. You can use the sample provided below.

## About this task

In this example, you have a file containing customer names and you want to generate an ID for each customer. You can use the following XML sample as input:

```
<customers>
   <customer>
      <firstName>Grover</firstName>
      <lastName>Truman</lastName>
   </customer>
   <customer>
      <firstName>Millard</firstName>
      <lastName>Roosevelt</lastName>
   </customer>
   <customer>
      <firstName>Theodore</firstName>
      <lastName>Garfield</lastName>
   </customer>
</customers>
```

The output structure should be the same as the input with an added id element. ![](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/use_routine_01_map.png)

## Procedure

1. Drag the input customer element to the corresponding output element to map the customer names.
2. From the Functions tab, drag a Java function and drop it on the id element.
3. Double-click the Java function and enter routines.DataMasking in the Class Name field and createRandomString in the Method Name field, then click OK.

   ![](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/use_routine_02_java.png)
4. Drag and drop a Constant function on the Java function.

   The routine used in this example requires a parameter that indicates the number of characters in the string to generate.
5. Double-click the Constant function and enter the length of the string you want to generate, 15 for example.
6. In the Data Type drop-down list, select Integer (32) and click OK.

   ![](https://help.qlik.com/talend/en-US/data-mapper-user-guide/Resources/images/use_routine_03_constant.png)
7. Optional: Add another Constant function below the first one to add a list of characters allowed in the generated string.

## Results

Your map in now configured. You can use the Test Run feature to see the result. In this example, the following output is returned:

```
<root>
  <customer>
    <firstName>Grover</firstName>
    <lastName>Truman</lastName>
    <id>tc2m9HQ9BQjbS7h</id>
  </customer>
  <customer>
    <firstName>Millard</firstName>
    <lastName>Roosevelt</lastName>
    <id>BcTd14JScXQQyjP</id>
  </customer>
  <customer>
    <firstName>Theodore</firstName>
    <lastName>Garfield</lastName>
    <id>BBCUINwgqXUh9ls</id>
  </customer>
</root>
```