Skip to Content

field duplication in HCI


I have requirement to duplicate the field as many times as the source field is more than 200 .

If field_name (source field) is more than 200 character then the target field(Tag_name ,0..*) should be updated with 200 char . Now target field(Tag_name ,0..*) should be duplicated and update with next more than 200 char ( and so on.

please help me to achieve this logic

Add comment
10|10000 characters needed characters exceeded

  • Hi Anurag

    It would be helpful, if you showed a couple of examples of input and the desired output., in order to clarify the mapping a bit.



  • Hi Morten,

    below is my requirement



    <FieldName> MessageText</FieldName>

    <FieldValue> text (unlimited)</FieldValue>




    <Tagname>upto 200 char</Tagname>



    <Tagname>201 to 400 char</Tagname>

    </Tag> . . .




    So if the source FieldName is "MessageText " and FieldValue is Text(it can be any number) then

    every <Tagname> should be truncated to 200 char.. If suppose <Fieldvalue> is 600 char then three <Tagname> should be created each 200 char.

    Also <Tag> should be created as many times as <Tagname> is creating ..

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 16 at 02:00 PM

    Hi Anurag

    There are two things, you need to accomplish:

    1. Extract the value of the FieldValue element paired with the FieldName element containing the string "MessageText"
    2. Split that value into a number of strings of length 200 and possibly a last string shorter than 200 characters

    You can do both in a single script. Here's the code:

    def void splitString(String[] fieldName, String[] fieldValue, String[] newLength, Output output, MappingContext context) {
        // Find the FieldValue belonging to the FieldName value "MessageText".
        def originalText = fieldValue[fieldName.findIndexOf { name -> name == "MessageText"}]
        def len = newLength[0].toInteger()
        def smallerStrings = originalText.toList().collate(len)
        smallerStrings.each { l ->

    Here's how to wire the script up in your mapping:

    Note that the FieldName and FieldValue elements both have their context set to the root element, to remove any context changes.

    Also note that I pass the length, you want to split the string into, as a parameter. I used the value 10 for testing. Change this to 200, or update the script to hardcode that value.

    Here's the result when I execute the mapping:

    Splitting the string into smaller strings is achieved by that originalText.toList().collate(len) construct. There are more effective ways to do that, but none that are shorter :-)



    mapping.png (58.6 kB)
    result.png (46.4 kB)
    Add comment
    10|10000 characters needed characters exceeded