Skip to Content
Author's profile photo srinu peram

Helpful UDFs – 1

Dear Users,

Here are some UDFs that might me helpful in your business scenarios.

1. UDF for Date Conversion :

          This UDF is used to convert the given date into required time zone and date format, it takes actual date as first input, required time zone as second input and format as third input which is validated based upon the second input. it validates the format of the both inputs and if true, returns actual date otherwise throws an exception. To use this, we need to import the UTIL and TEXT pages.


Code :

                       DateFormat df1 =new SimpleDateFormat(DateFormat);




                        DateFormat df2 = new SimpleDateFormat(DateFormat);


                       String target = ” “;




                       Date d = df1.parse(CurrentDate);


                      target = df2.format(d);


                     catch( Exception e)


                    Return target;

  Input :


Output :


2. Combining Array Elements:

             This is Queue type UDF.It takes a string and delimiter value as arrays and combines all the array elements with a delimiter and sends as single value.


Code :

                  String res=””,delimiter=””;

                  res = StrArray[0]

                  delimiter = Separator[0];

                  for(int i=1;i<strArray.length;i++)

                  res = res+delimiter+StrArray[i];


Input and Output :


3 . Checking Mandatory Field

                      This is a simple type UDF. It takes a single value and checks if the node exists or not. If the node exists, it returns same value, Otherwise it throws an exception.


Code :

                  if (!var1.equals(“”)&&(var1.length()>0))

                  return var1;


                  throw new RuntimeException(“This field is mandatory : value is missing”);


Input   :


Output     :


4. Remove Domain Name

               This is simple type UDF. It takes a mail id as input and removes the domain name.


Code :

                  String Pattern = “”;

                  String StrippedString = str.replaceAll(pattern,””);

                  return strippedstring;


                                    Input :                                                                            Output                                                                                                        


5. Checks for the end of the List

                      This is Queue type UDF. It takes a set of values as input and sends all the values to output until the end of the list field appears for the first time.


Code :

                 int i = 0;


                 int j = 0;

                 // check for the presence of EOD

                 while (!var1[i].equals(“EOD”))




                  // add the values till EOD is not present




                                         Input :                                                             Output


Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Raghuraman S
      Raghuraman S


      Already posted some of these UDFS in


      Useful UDFS-Part 2

      Author's profile photo srinu peram
      srinu peram
      Blog Post Author

      Hi Raghu, I have removed the existing UDF.

      Author's profile photo Raghuraman S
      Raghuraman S

      Great Srinu..:)

      Author's profile photo suman sourabh
      suman sourabh

      Thanks Srinu for sharing these logics.

      For the 4th UDF to remove the Domain name from the input, your code is working only for fixed domain.

      e.g. for input your code wont work,

      So for generic solution we can use some different logic like:




      int i = str.indexOf("@");

      String o = str.substring(0,i);

      return o;




      Author's profile photo srinu peram
      srinu peram
      Blog Post Author

      Hi Suman,

      That is also a good idea. As most of the requirements are on fixed domain, I shared that logic.

      Author's profile photo Former Member
      Former Member

      Hi Srinu,

      Thanks for spending time on sharing useful UDFs.

      Can you lease check the below mentioned code in last UDF:

      •    while (!Var1[i].equals("EOD"))
      •     result.addvalue(var1[i]);

      it should be :

      •    while (!var1[i].equals("EOD"))
      •   result.addValue(var1[i]);



      Author's profile photo srinu peram
      srinu peram
      Blog Post Author

      Hi Yeshwanth,

      Thanks for correcting. Updated 🙂