cancel
Showing results for 
Search instead for 
Did you mean: 

How to Pass List as Input to Webservice

Former Member
0 Kudos

Hello All,

For our one of the PI webservice we were using single values as input parameters but now it should accept multiple values or list as input. Please find below mentioned code :

private final List<String> purchaseOrderValues = new ArrayList<String>();

SPI_OrderStatus model = new SPI_OrderStatus();

  IWDMessageManager manager = wdComponentAPI.getMessageManager();

   

  IPublicSPIComponent.ISearchSPINode searchNode = wdContext.nodeSearchSPI();

  IPublicSPIComponent.ISearchSPIElement searchElement = wdContext.currentSearchSPIElement();

  OrderStatus_Request_Columns request = new OrderStatus_Request_Columns(model);

  if(!this.purchaseOrderValues.isEmpty() || searchElement.getPurchase_Order() != null){

   if(this.purchaseOrderValues.isEmpty()){

   this.purchaseOrderValues.add(searchElement.getPurchase_Order());

  }

request.setPurchase_Order(this.purchaseOrderValues);

     }

********************************

request.setPurchase_Order(this.purchaseOrderValues); on this line when we are setting Purchase_order as input list I am getting below mentioned error on this line.


java.lang.ClassCastException: Cannot cast class java.lang.String to interface com.sap.tc.cmi.model.ICMIModelClass


Please let me know how to add those mutiple values to webservice input.


Regards,

Mayank Saxena



Accepted Solutions (1)

Accepted Solutions (1)

govardan_raj
Contributor
0 Kudos

hi mayank,

this is occuring because , in yoru webserivce structure the node cardinality is 0..1 , so it cant accept multiple values , ask your PI /XI consultant to change the cardinality of that node to 0...n , then reimport that and implement above code.

Regards

Govardan Raj

Former Member
0 Kudos

Hi Govardan,

Thank you for your reply. PI team already change the cardinality to 0 to n by below mentioned changes.

<xsd:element name="Purchase_Order" type="xsd:string" minOccurs="0" maxOccurs="unbounded">

Is this correct ?

Regards,

Mayank

govardan_raj
Contributor
0 Kudos


Hi mayanka,

here for a node type = xsd:string wil not come ... and that min occurs and max occurs = unbounded is fine and correct ,

Regards

Govardan Raj

Former Member
0 Kudos

Hi Govardan,

Thank you for your quick reply. Could you please tell me what will be the value instead of string ?

Regards,

Mayank

govardan_raj
Contributor
0 Kudos

Hi mayank,

that type itself will nto come for node... that attribute type is only for the feilds in the node and not for node...

Regards

Govardan

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello I did this to convert.

private List<String_Item> convertStringListToStringItemList(List<String> stringList, <Model_Name> model ){

         

            List<String_Item> retVal = new ArrayList<String_Item>();

         

            String_Item stringItem;

         

            for(String s : stringList){

               

                  stringItem = new String_Item(model);

                  stringItem.setItem(s);

               

                  retVal.add(stringItem);

            }

         

            return retVal;

      }


and while setting the request values:

request.set<attribute_name>(this.convertStringListToStringItemList(this.<Attribute_Name>, model);


BTW Thank you for your help.


Regards,

Mayank Saxena

former_member197472
Active Participant
0 Kudos

Hi Mayank,

It is type cast exception.. it is because of difference in source and destination fields'  data types(as govardan said).

you will have to create elements of subnode and loop over string list and set field values one by one.

Also, Dont we bind in request to node again after creation ?

Regards,

Amey