From the controller take the value of the input

I have created this wirzard to add a reason for cancellation of the production order, with this value selected assign it to all the manufacturing orders that make up the production order
How can I get this data from the controller?
By pressing the button I am reaching a controller method, but I don’t know how to capture that data to send it to the manufacturing orders.

I think I solved it this way

The only thing is that it doesn’t work for me is that the wizard is not hidden

image

Hello

Here I am assuming that cancelReason is the real field you have added in ProductionOrder domain model referenced to com.axelor.apps.base.db.CancelReason. (Correct me if it’s not the case.)
And as you have specified canNew=’ false’ and canEdit= ’ false’, User can only select existing records only. So

  • you don’t need to create new separate record of type CancelReason
  • you can access the selected value form context directly from productionOrder record something like
ProductionOrder prodOrder = request.getContext().asType(ProductionOrder.class);
System.out.println(prodOrder.getCancelReason().getName());
System.out.println(prodOrder.getCancelReasonStr());

If it’s a dummy field in this form, you can still access it directly from context

Context context = request.getContext();
Map cancelReasonMap = (Map<String, Object>) context.get("cancelReason");
CancelReason cancelReason = Beans.get(CancelReasonRepository.class).find((long) cancelReasonMap.get("id"));
System.out.println(context.get("cancelReasonStr"));

So this will return you the existing cancelReason record from database and you can use it as required.

Thank you.

Hello and thanks for answering
I have two options, add the cancelReason field to ProductionOrder or not add it.
In this case I have not added it, no, I did not do it that way, why? because I want is a button to perform a mass action, in a group, in batch to affect with a single button all the ManufOrder that belong to the production order, in this case what I require is the following: if I cancel the production order production, all manufacturing orders associated with this production order should be canceled.

The first thing is that I did not know how to obtain data from the form, I already saw that it can be obtained in several ways, the code that I show in the image worked for me and in the previous message I indicated that it had already worked for me, I took the cancelReason and add to all the manuforder, in the end I only had one problem: the wizard does not hide when I finish adding the cancelReason

Hello

Specify response.setCanClose(true); at last in your Controller method to close that popup window.

Thank you

change of

Beans.get(ManufOrderService.class).saveManufOrders(manufOrders);    
	    Beans.get(ProductionOrderService.class).saveOrderProduction(productionOrder);

response.setCanClose(true);
response.setInfo(I18n.get(ProductionExceptionMessage.MANUF_ORDER_CANCEL));
response.setReload(true);

change it to

Beans.get(ManufOrderService.class).saveManufOrders(manufOrders);    
	    Beans.get(ProductionOrderService.class).saveOrderProduction(productionOrder);
response.setInfo(I18n.get(ProductionExceptionMessage.MANUF_ORDER_CANCEL));
response.setReload(true);
response.setCanClose(true);	 

I’m going to try it

no, it didn’t work, the cancellation is carried out, the information message is displayed, the wizard is reset, but it remains visible

Hello

Try to specify close at the last in onClick attribute of button in form Like
<button name="cancelConfirmBtn" title="Confirm cancellation" colspan="4" coloffset="4" onclick="action production-order-the-cancel,close"/>

Or can try another way

Remove response.setReload(true); from the controller and add that same from action-view (which open this xml form) as view-param
<view-param name="popup" value="reload"/>

Hope this will help you

Thank you

1 « J'aime »

The first option you gave me worked, thank you!!!

So now no need to add response.setCanClose(true); in controller

thanks… very thank you

Ce sujet a été automatiquement fermé après 30 jours. Aucune réponse n’est permise dorénavant.