cancel
Showing results for 
Search instead for 
Did you mean: 

New to PI and java

Former Member
0 Kudos

I ahve to create a UDF, basically it states that if variable #1 is equal to "CostCenter" then I will have to take the last 4characters of variable #2, How would that be written in a UDF?

Accepted Solutions (1)

Accepted Solutions (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Create two arguments var1 and var2 as type String and method name returnLastFourChars

Do the following

public String returnLastFourChars(String var1, String var2, Container container) throws StreamTransformationException{

String result="";
if (var1.equals("CostCenter")){
   result = var2.substring(var2.length()-4, var2.length());
}
return result;
}

Map var1,var2 to the input of the UDF function and output map to the target field.

Answers (2)

Answers (2)

former_member181962
Active Contributor
0 Kudos

YOu might use the below code:

SubStringEx subEx = new SubStringEx();

if var1.equals("CostCenter")

{

String last4Digits = subEx.getLastnCharacters(var2,4);

}

return last4Digits;

Former Member
0 Kudos

You can use standard functions to achieve your issue. IF stateme

nt and text operations

Former Member
0 Kudos

Yeah but I want to write a UDF for scalability purposes