Topic:   How to convert an webMethods arraylist into an IDATA docuent?
May 18, 2013 16:40 6 Replies 4510 Views Shuvaday
Prev Next
Topic Replies (6)
  1. 1
    idnkx user

    Shuvaday

    Hi All
    I am a newbie in webmethod.
    In one of my java service i need to convert an arraylist into an IData Document.
    Could someone help with the conversion,as i am getting typecasting error while executing below code:
    IData[] doc = (IData[])sList.toArray();//sList is the arraylist.
    Thanks in advance for the help.

    1
    idnkx user

    Pavan

    check the below code in order to read from a webMethods document list into wM Java service through IData object:

    IData[] doclist = IDataUtil.getIDataArray(pipelineCursor, "doclist" );

    This will read wM doc list content into your IData object.

    if ( doclist != null)
    {
    for ( int i =0; i < doclist.length; i++ )
    {

    your logic.........

    At last IDataUtil.put(pipelineCursor,"outlist",outList);
    ..

    pipelineCursor.destroy();

    1
    idnkx user

    Shuvaday

    Hello Pranav
    Thats fine....but could you please tell me where am i getting wrong in the below cod:
    IDataCursor pipelineCursor = pipeline.getCursor();
    ArrayList sList = new ArrayList();


    IData Student[] = null ;
    if ( Student != null)
    {
    for(int i =0;i IDataCursor sCursor = Student[i].getCursor();
    IData sDetails = IDataFactory.create();
    IDataCursor fdc = sDetails.getCursor();
    IDataUtil.put(fdc,"name",IDataUtil.getString(sCursor,"name"));
    IDataUtil.put(fdc,"class",IDataUtil.getString(sCursor,"class"));
    sList.add(sDetails);
    sCursor.destroy();
    }
    }
    pipelineCursor.destroy();

    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();

    // Doc
    IData [] doc = IDataUtil.getIDataArray(pipelineCursor_1,sList);

    IDataUtil.put( pipelineCursor_1, "Doc", doc );
    pipelineCursor_1.destroy();
    ---------------------------------------------------------
    i want to convert the arrayList(sList) to an array before putting it in the output Documnet doc.

    1
    idnkx user

    Pavan

    Hi,

    No need to define your code/logic, just follow the below instructions:

    1) Create a empty service with your required Inputs and outputs.

    2) Go to Tools and click on Generate code option.

    3) Select for implementing this service option and then click on next.

    4) Select in Specification both input and output, Select in which fields all fields option

    5) Click on finish

    6) You will receive a pop-up message "The generated code has been copied to the clipboard"

    7) Click on ok and right click on your java service body and paste it.

    I have defined the input as a document list variable as "docList" and inside docList i got two variables var1 and var2, then i have given output a document as "doc" and inside i got two variable var 1 and var2

    When i ran the above steps i got the below code :


    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();

    // docList
    IData[] docList = IDataUtil.getIDataArray( pipelineCursor, "docList" );
    if ( docList != null)
    {
    for ( int i = 0; i < docList.length; i++ )
    {
    IDataCursor docListCursor = docList[i].getCursor();
    String var1 = IDataUtil.getString( docListCursor, "var1" );
    String var2 = IDataUtil.getString( docListCursor, "var2" );

    [b] // Here you can define your logic[/b]

    docListCursor.destroy();
    }
    }
    pipelineCursor.destroy();

    // pipeline
    IDataCursor pipelineCursor_1 = pipeline.getCursor();

    // doc
    IData doc = IDataFactory.create();
    IDataCursor docCursor = doc.getCursor();
    IDataUtil.put( docCursor, "var1", "var1" );
    IDataUtil.put( docCursor, "var2", "var2" );
    docCursor.destroy();
    IDataUtil.put( pipelineCursor_1, "doc", doc );
    pipelineCursor_1.destroy();


    But I am not sure how you will be making an docList or array list with multiple documents to a single document :(

    1
    idnkx user

    Raj Kumar

    Check the below link:

    [url=http://www.idnxchange.com/webmethods-interview-questions/3-webmethods-Interview-questions/127-how-to-convert-document-list-to-document-if-document-list-contain-documents-and-documents-contain-strings-field-how-to-convert-.html]Document list to Document[/url]

    1
    idnkx user

    Shuvaday

    Thanks a lot for your replies...
    it helped :)

Leave a Reply
Guest User

Not sure what course is right for you?

Choose the right course for you.
Get the help of our experts and find a course that best suits your needs.


Let`s Connect