Hello Ronald,
I hope this will be of help.
The service you are calling is createPartyEmailAddress requires
authentication so you need to send the userLogin value to it.
Something like this:
// perform actions as the system user
GenericValue userLogin =
delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId",
"system"));
input = UtilMisc.toMap("userLogin", userLogin, "emailAddress",
email, "partyId", "_NA_", "fromDate", fromDate, "contactMechPurposeTypeId",
"OTHER_EMAIL");
Map serviceResults =
dispatcher.runSync("createPartyEmailAddress", input);
if (ServiceUtil.isError(serviceResults)) {
throw new
GenericServiceException(ServiceUtil.getErrorMessage(serviceResults));
}
Thanks & Regrads
--
Pranay Pandey
On Thu, Jun 5, 2008 at 9:38 PM, RolandH <[EMAIL PROTECTED]> wrote:
> Hello Pranay,
>
> great work :)
> Perfect for beginners like myself.
>
> As I'm trying to write my first service, implemented with java, maybe you
> could add a few words about that in your tutorial.
>
> Maybe someone could answer a question about that:
> how do I call services which need authentication (e.g.
> createPartyEmailAddress from framework/party/services)?
> What I'm doing:
> my service requires already authentication, which works, creating persons
> is no problem at all (createPerson has auth="false", which i don't get why
> today, but i'm sure that's because of my limited knowledge of ofbiz)
> calling createPartyEmailAddress throws:
> [ ServiceDispatcher.java:522:ERROR] Error in Service
> [partyContactMechPermissionCheck]: You must be logged in to complete the
> [Party contact mech permission logic] process.
> a snipped of my code is below.
>
> Thanks again for this tutorial and thanks for any answers,
>
> Roland
>
> --- code ---
> [...]
> Map createPartyEmailAddressMap = UtilMisc.toMap(
> "emailAddress", context.get("emailAddress"),
> "contactMechPurposeTypeId", "PRIMARY_EMAIL",
> "login.username", context.get("login.username"),
> "login.password", context.get("login.password"));
> [...]
>
> // create Person
> Map createPersonResult = dispatcher.runSync("createPerson",
> createPersonMap);
> if (ServiceUtil.isError(createPersonResult)) {
> return createPersonResult;
> }
>
> // create EmailAddress
> createPartyEmailAddressMap.put("partyId",
> createPersonResult.get("partyId"));
> Map createPartyEmailAddressResult =
> dispatcher.runSync("createPartyEmailAddress", createPartyEmailAddressMap);
> if (ServiceUtil.isError(createPartyEmailAddressResult)) {
> return createPartyEmailAddressResult;
> }
>
>