IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.



#Automation


#Applicationintegration
#webMethods
#Integration
 View Only
Expand all | Collapse all

get count of string list for a particular string

  • 1.  get count of string list for a particular string

    Posted 10/03/17 05:10 AM

    Input is string list which contains multiple strings Ex values: Ram,Raj,Rahim,Rahim,Ram,Raj

    When condition satisfies with Ram,get the count of Ram in the output.
    Similar for Rahim and Raj

    Thanks in advance,
    Niveditha


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: get count of string list for a particular string

    Posted 11/06/17 11:24 PM

    Hi Niveditha,

    There are many ways to achieve this requirement. One way is to use java service. Please see below steps.

    1)In the designer create a Java Service (ex: “GetCountJava” ) (rt click-> New-> Java Service)

    2)Select Input/Output tab
    Add following variables in the input section:
    a)Insert variable of type StringList (name it as “listOfNames” )
    b)Insert variable of type String (name it as “searchName” )

    Add the following variable in the output section:
    a)Insert a variable of type String(name it as “count” )
    (Please see attached image(1.png) for your reference )

    1. Now select source tab and use following code in the “GetCountJava” method
      IDataCursor pipelineCursor = pipeline.getCursor();
      String listOfNames = IDataUtil.getStringArray( pipelineCursor, “listOfNames” );
      String searchName = IDataUtil.getString( pipelineCursor, “searchName” );
      int count=0;
      for (String string : listOfNames) {
      if(searchName.equals(string)){
      count++;
      }
      }

       IDataUtil.put( pipelineCursor, "count", count );
      pipelineCursor.destroy();
      

    (Please see attached image(2.png))

    The above code will read list of names and a name which is used to match against the list. Whenever there is a match count variable is incremented.

    4)Run the service and input list of names and name in the input section(result1.png . The output will give the count.
    (Please see attached image result1.png)

    Please revert back if you need any assistance.

    Regards,
    Shiva




    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods