Skip to Content

field duplication in HCI

Hi,

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.

    Regards,

    Morten

  • Hi Morten,

    below is my requirement

    source

    <Dynamicalue>

    <FieldName> MessageText</FieldName>

    <FieldValue> text (unlimited)</FieldValue>

    </Dynamicalue>

    Target

    <Tag>

    <Tagname>upto 200 char</Tagname>

    </Tag>

    <Tag>

    <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 ..

  • Follow
  • Get RSS Feed

3 Answers

  • 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:

    import com.sap.it.api.mapping.*
    
    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 ->
            output.addValue(l.join())
        }
    
    }

    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 :-)

    Regards,

    Morten


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

  • Aug 15 at 10:28 PM

    Hello Morten Wittrock,

    I have a similar case, I have to move from a field 0: 1

    field1: "value1, value2, value3"

    To a structure 0: *

    <item>

    <field1> value1 </field1>

    </item>

    <item>

    <field1> value2 </field1>

    </item>

    <item>

    <field1> value2 </field1>

    </item>

    I am new to UDF and need help, any suggestions.

    Thank you,

    Greetings.

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 16 at 03:21 PM
    Add comment
    10|10000 characters needed characters exceeded