0

can any one help me pleaze , i have a entity named Person and formateur extend from this entity so i want to add a formateur the probleme that i need the id of the table Person how i can get it plz

public static Map<String, Object> createFormateur(DispatchContext dctx, Map<String, ? extends Object> context) {
Map<String, Object> result = ServiceUtil.returnSuccess();
Delegator delegator = dctx.getDelegator();
try {
    GenericValue formateurAdd = delegator.makeValue("twFormateur");


    formateurAdd.setString("partyId", context.toString());

    formateurAdd.setNonPKFields(context);
    // Creating record in database for OfbizDemo entity for prepared value
    formateurAdd = delegator.create(formateurAdd);
    result.put("partyId", formateurAdd.getString("partyId"));
    Debug.log("==========Thisis my first Java Service implementation in Apache OFBiz. OfbizDemo record created successfully with ofbizDemoId: "+formateurAdd.getString("partyId"));
} catch (GenericEntityException e) {
    Debug.logError(e, module);
    return ServiceUtil.returnError("Error in creating record in OfbizDemo entity ........" +module);
}
return result;

}

hind
  • 11
  • 5

1 Answers1

1

If you need to get a single key from context, partyId for example, you can try :

String partyId = (String)context.get("partyId");

in this case you probably want to populate all the information of the context into your GenericValue, you can try :

GenericValue formateurAdd = delegator.makeValidValue("twFormateur", context);
Florient
  • 236
  • 1
  • 9
  • thanks it work good, i do the same but i forget to do cast from object to String thanks – hind Nov 15 '17 at 11:10