Clearing the contents of List/Map

It is a very common need to clear the contents of a list or a map, especially when you are constructing a list or a map inside a loop.In LC 8.2 we have added a function to which allows you to clear the list/map contents

But for those of you using previous versions you can copy the following script and paste it in the ExecuteScript component

import java.util.*;
ArrayList list = patExecContext.getProcessDataValue(“/process_data/listOfPrincipalRef”);

((HashMap) patExecContext.getProcessDataValue(“/process_data/inputMapOfAttachments”)).clear();
System.out.println(“******Got list ,size is “+list.size());
((ArrayList) patExecContext.getProcessDataValue(“/process_data/listOfPrincipalRef”)).clear();
System.out.println(“******Got List,size is “+list.size());

Where listOfPrincipalRef is a list variable defined in your process,inputMapOfAttachments is a variable of type map defined in your process

Let me know if you have any questions

thanks

girish

Advertisements

2 responses to “Clearing the contents of List/Map

  1. Hi,

    I try to use the execute script but I’m a little bit lost.

    I have a process with a loop. I try to add a string into a list each time I enter in the loop.

    here is my code :

    —————————————————
    import java.util.List;
    import java.lang.String;

    List loginListe = patExecContext.getProcessDataListValue(“/process_data/ListeNplusUn”);

    String nplusun = patExecContext.getProcessDataValue(“/process_data/@nplusun”);

    loginListe.add(“nplusun”);

    patExecContext.setProcessDataListValue(“/process_data/ListeNplusUn”,loginListe);

    ———————————————-
    The problem is a runtime error : “outofmemory “. If I take off the last instruction (the setProcessDataListValue) the error doesn’t appear and if there is no loop but the last instruction is present, there is no error.

    I don’t know if it is the good place to ask my question. Sorry if it doesn’t.

  2. loginListe.add(”nplusun”); is replaced by loginListe.add(nplusun); of course 😛

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s