cancel
Showing results for 
Search instead for 
Did you mean: 

Manipulate Dates in XI Message Mapping

Former Member
0 Kudos

Hello all,

I have a problem in which I need to take a date from my source file and manipulate this date to help produce my target structure.

<i><b>This is not my actual XML</b></i>

<source root>
  <field 1>A</field 1>
  <field 2>Any value</field 2>
  <field 3>Next value</field 3>
  <field 4>20070201</field4>
</source root>

Consider the above XML as my source. I would like to have logic in the message mapping that will check the value of a field (field 1) and based on it's value add or subtract days from the date value provided.

This would be my output for adding ten (10) days if '<b>field 1</b>' has a value of '<b>A</b>'

<target root>
  <target 1>A</target 1>
  <target 2>Any Value</target 2>
  <target 3>Next Value</target 3>
  <target 4>20070211</target 4>
</target root>

This would be my output for subtracting five (5) days if '<b>field 1</b>' has a value of '<b>B</b>' (Same source file)

<target root>
  <target 1>B</target 1>
  <target 2>Any Value</target 2>
  <target 3>Next Value</target 3>
  <target 4>20070127</target 4>
</target root>

As you can see there is a field in my source system that will tell me what type of logic to perform. The problem that I am having now is that the message mapping functions that currently exist are not helping me satisfy this requirement. I have viewed several forums and tried several of the suggestions given but nothing seems to help. Does anyone know how to solve this problem? Is there a UDF that anyone has used that would help me in solving this requirement? The solution should be dynamic to account for leap years as well as for the different days that each month has.

Answers received will be rewarded with points.

Thanks in advance for the help that you provide.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

UDF was helpful. However, the requirement was easier if the dates could be provided as is to XI and do a 1 to 1 mapping. With minor changes to the UDF, this would have solved our problem.

henrique_pinto
Active Contributor
0 Kudos

Come on, that UDF was exactly what you required.

Give the man the points.

Henrique.

former_member214364
Active Contributor
0 Kudos

Hi,

Here i am sending UDF code,which takes date(format:yyyyMMdd) as input and does addition or subtraction operations based on <field 1> value,return the result date(format:yyyyMMdd) as string value.

public String GenerateDate(String date_input, String field1,Container container){

//Here "date_input" and "field1" are inputs for this UDF

int date = Integer.parseInt(date_input);

Calendar cal;

int day = date % 100;

int month = (date/100) % 100 - 1;

int year = date / 10000;

cal = Calendar.getInstance();

cal.set(year, month, day);

/implement addition or subtraction logic here as your needs/

if (field1 == "A")

cal.add(Calendar.DATE, 10);

else if(field == "B")

cal.add(Calendar.DATE, -5);

day = cal.get(Calendar.DATE);

month = cal.get(Calendar.MONTH)+ 1;

year = cal.get(Calendar.YEAR);

date = year * 10000 + month * 100 + day;

return (""+date);

}

if you need any other details regarding this UDF, plz let me know.

Cheers,

Jag