Update view fields from a popup form view

Hello,

Could you please suggest how to update the values of the fields in a form with the ones entered from a popup window? Meanwhile, the model of the main form and popup form is the same.

For example, I would like to change the values of the « product-form » update from the « stock-product-tariff-popup-form. »

My solution is not working. The code snippet to look at:
axelor-stock/views/Product.xml:



ProductController.java:

public void handleSubmissionForm(ActionRequest request, ActionResponse response) {
    Product product = request.getContext().asType(Product.class);

    if (product != null) {
      Product updatedProduct = Beans.get(ProductService.class).handleSubmissionForm(product);

      response.setValue("_tariffStatus", updatedProduct.getTariffStatus());
      response.setValue("_salePrice", updatedProduct.getSalePrice());
      response.setValue("_startDateTime", updatedProduct.getStartDateTime());
      response.setValue("_endDateTime", updatedProduct.getEndDateTime());

      response.setReload(true);
    } else {
      response.setError("Product not found");
    }
  }

ProductService.java:

@Transactional
  public Product handleSubmissionForm(Product product) {
    Product existingProduct = productRepo.find(product.getId());
    //Product existingProduct = productRepo.all().filter("self.id = ?1", product.getId()).fetchOne();

    if (existingProduct != null) {
      existingProduct.setTariffStatus(product.getTariffStatus());
      existingProduct.setSalePrice(product.getSalePrice());
      existingProduct.setStartDateTime(product.getStartDateTime());
      existingProduct.setEndDateTime(product.getEndDateTime());

      productRepo.save(existingProduct);

      return existingProduct;
    } else {
      throw new RuntimeException("Product not found");
    }
  }

Hello
Welcome to the Axelor Community !!

You don’t need to call controller method or service method just to save the entered value on same record.

You can open same record on popup by specifying id for _showRecord context key in action-view using which you are opening your popup.

    <action-view name="action-stock-product-tariff-popup-form" title="Product" model="com.axelor.apps.base.db.Product">
		<view type="form" name="stock-product-tariff-popup-form"/>
		<view-param name="popup" value="reload"/>
		<view-param name="forceEdit" value="true"/>
		<context name="_showRecord" expr="eval: id"/>
	</action-view>

And one more modification in this action-view is, reload your popup so that your main form is having latest saved record.
<view-param name="popup" value="reload"/>

And you can specify onSave="save,close" if you want to close your popup when you click on save icon from the popup form.

Thank you