Error in script of Connector Mail

1
0
-1

Hi all,

I would send an email to all user of my company using a system task with a mail connector where in the To field I add a script that select all user and create a string with all email.

But this is the exception that I obtain.

java.lang.reflect.InvocationTargetException<br />
        org.bonitasoft.engine.bpm.connector.ConnectorExecutionException:<br />
        org.bonitasoft.engine.core.connector.exception.SConnectorException:<br />
        org.bonitasoft.engine.expression.exception.SExpressionEvaluationException:<br />
        Script throws an exceptionSExpressionImpl [<br />
            name=getUserMail,<br />
            content=<br />
            <br />
            import org.bonitasoft.engine.search.*;<br />
            import org.bonitasoft.engine.identity.*;<br />
            <br />
            SearchOptionsBuilder so = new SearchOptionsBuilder(0, 100);<br />
            SearchResult<User> userResult = apiAccessor.getIdentityAPI().searchUsers(so.done());

    String mailto = new String();<br />
            for (User u : userResult)<br />
            {<br />
                UserWithContactData proUser = apiAccessor.getIdentityAPI().getUserWithProfessionalDetails(u.getId());<br />
                mailto += ", "+proUser.getContactDactivityInstanceIdata().getEmail();<br />
            }<br />
            <br />
            return  mailto;<br />
            ,<br />
            returnType=java.lang.String,<br />
            dependencies=[SExpressionImpl [    name=apiAccessor,<br />
                                            content=apiAccessor,<br />
                                            returnType=org.bonitasoft.engine.api.APIAccessor,<br />
                                            dependencies=[],<br />
                                            expressionKind=ExpressionKind [interpreter=NONE,<br />
                                                                            type=TYPE_ENGINE_CONSTANT<br />
                                                                            ]<br />
                                        ]<br />
                        ],<br />
            expressionKind=ExpressionKind [interpreter=GROOVY,<br />
                                            type=TYPE_READ_ONLY_SCRIPT<br />
                                        ]<br />
        ]

Thanks for attention,

Francesco

Comments

Submitted by poltowers on Thu, 04/24/2014 - 06:26

HI.....

Resolve this problem???

I need help..

Thanks..

1 answer

1
0
-1

hello Francy,

having a look in your code and I see a few mistakes:

in line num 5 in the second block of code: it says: mailto += ", "+proUser.getContactDactivityInstanceIdata().getEmail();

and should be:

mailto += ", "+proUser.getContactData().getEmail();

SearchResult userResult --> you cannot iterate over the searchResult object directly. You need to get the result of the search first (with userResult.getResult() method)!

Try something like this:

        SearchOptionsBuilder so = new SearchOptionsBuilder(0, 100);
        SearchResult<User> userResult = identityAPI.searchUsers(so.done());
        List<User> userList = userResult.getResult();
        String mailto = new String();
        for (User user : userList) {
                UserWithContactData proUser = identityAPI.getUserWithProfessionalDetails(user.getId());
                if (proUser != null && proUser.getContactData() != null) {
                        mailto += ", " + proUser.getContactData().getEmail();
                }
        }
        System.out.println(mailto);

Let me know if this helps. Cheers, Jordi

Comments

Submitted by jordi.anguela_1 on Mon, 04/28/2014 - 12:51

Going one step further... why don't you create a new email list like : "all_company@xxx.com" and set all your company members to that list?

then, you will only need to send a single email to that list. Then the email will be propagated by your email server to whole company. easier, no?

Bare in mind that in your code you are doing a request to the Execution Engine (Bonita DB) per each user in the system to retrieve the email information (not very performant, let's say). If this is the way you want to go, I recommend you to implement your own command, that retrieves all user emails in your system in a single request. Check the CommandAPI for more info (http://documentation.bonitasoft.com/javadoc/api/6.2/org/bonitasoft/engin...)

Regards, Jordi

Notifications