I have a UI form in admin with store switcher. I need store_id in post data.

enter image description here

As all can see store_id in url when I change store from store switcher but once I submit it I am not getting any store value in post data. So I think I need to set store value in a hidden field. I don't know I am on right track or not. Please help guys if anyone faced this issue before.

2 Answers 2


I just need to set store id in DataProvider file like below.

namespace Vendor\Module\Model\Providers;
use Vendor\Module\Model\ResourceModel\Company\CollectionFactory;

class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
     * @var array
    protected $loadedData;

     * @param string $name
     * @param string $primaryFieldName
     * @param string $requestFieldName
     * @param CollectionFactory $taskCollectionFactory
     * @param array $meta
     * @param array $data
    public function __construct(
        CollectionFactory $companyCollectionFactory,
        \Magento\Framework\App\Request\Http $request, 
        \Magento\Store\Api\StoreRepositoryInterface $storeRepository,        
        array $meta = [],
        array $data = []
    ) {
        $this->collection = $companyCollectionFactory->create();
        $this->request = $request;
        parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);

     * Get data
     * @return array
    public function getData()
        if (isset($this->loadedData)) {
            return $this->loadedData;
        $items = $this->collection->getItems();
        foreach ($items as $item) { 
            $this->loadedData[$item->getEntityId()] = $item->getData();

        return $this->loadedData;


<field name="store_id" sortOrder="65" formElement="hidden">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="source" xsi:type="string">company</item>
  • what if i am using for new and edit action from same . so how can i set store id for new action? Commented Nov 29, 2018 at 12:57
  • 1
    @RutveeSojitra Actually on add form there will be no option of store switcher so it will save as store_id 0 while add. I got inspired from product add/edit form. Commented Nov 30, 2018 at 3:17
  • Thanks ramkishan . Actually i am migrating magento1 to magento2 and in my magento1 there is functionality to save store id when we add so am finding same for magento2. But no luck Commented Nov 30, 2018 at 4:30
  • @Ramkishan Suthar What If the form is empty that means is New how to populate the field? as $this->loadedData returns Array() Commented Jun 28, 2019 at 16:05
  • @JulianoVargas while adding a new entry store_id will be saved as 0. I checked in default product add/edit form. Commented Jun 29, 2019 at 5:21

Kindly use getting all get, post, and url values in the controller action:

        /** @var \Magento\Backend\App\Action $this*/
        /** @var array $params*/
        $params = $this->getRequest()->getParams();

You can also get each value by:

         /** @var string $store*/
        $store = $this->getRequest()->getParam('store');
  • Thanks @milind for answer. I got the solution and posted it as answer. Commented Nov 24, 2018 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.