Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to find the view_id using rpc call from JavaScript

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptrpc
2 Odgovori
6455 Prikazi
Avatar
Varun Samvedi

Hello,

I am using Odoo 15.

I am trying to call do_action from JavaScript. In my do_action call, I need to return an action and a view, but I only know the name of my view.

I tried to do the below rpc call to find my view_id, but it isn't working.

rpc.query({
// Get view id
    model:'ir.model.data',
method:'xmlid_to_res_model_res_id',
args: ['my_module.'my_view_name], // View id goes here
}).then(function(data){
​
 self.do_action({
name:'view name',
type: 'ir.actions.act_window',
res_model: 'my_model',
view_mode: 'form',
views: [[data[1], 'form']],
})

});

But this throws this error:

*****AttributeError: type object 'ir.model.data' has no attribute 'xmlid_to_res_model_res_id'*****

Please let me know the correct way to make​ rpc calls in Odoo 15.

Thanks.









0
Avatar
Opusti
Avatar
Varun Samvedi
Avtor Best Answer

Salaam Muhammad Bhai,

Yes it was very helpful.

I finally used this code (with some changes) :

rpc.query({
model: 'ir.model.data',
method: 'search',
args: [
[
['name', '=', 'name_of_my_view']
]
],
}).then(function(view_ids) {
if (view_ids.length > 0) {
var view_id = view_ids['res_id'];
// Do something with the view_id
self.do_action({
name: 'name_of_my_view',
type: 'ir.actions.act_window',
res_model: 'name_of_my_model',
view_mode: 'form',
views: [
[view_id, 'form']
],
})
} else {
console.log("View not found");
}
});

Thanks,

-Varun

0
Avatar
Opusti
Varun Samvedi
Avtor

Nope, I actually used your code itself!

I discarded the above code written by me.
But this website isn't allowing me to edit it due to lack of KARMA!

rpc.query({
model: 'ir.ui.view',
method: 'search',
args: [
[
['name', '=', 'VIEWNAME']
],
],
}).then(function(view_ids) {
if (view_ids.length > 0) {
var view_id = view_ids[0];
// Do something with the view_id
self.do_action({
name: 'VIEWNAME',
type: 'ir.actions.act_window',
res_model: 'MODELNAME',
view_mode: 'form',
views: [
[view_id, 'form']
],
})
} else {
console.log("View not found");
}
});

Avatar
MUHAMMAD Imran
Best Answer

To find the view_id for a specific view using an RPC call from JavaScript in Odoo, you can use the following code:


Copy code

rpc.query({

    model: 'ir.ui.view',

    method: 'search',

    args: [[['name', '=', 'view_name']]],

}).then(function (view_ids) {

    if (view_ids.length > 0) {

        var view_id = view_ids[0];

        // Do something with the view_id

    } else {

        console.log("View not found");

    }

});



In this code, replace 'view_name' with the name of the view for which you want to find the view_id. The code will perform a search for a view with a name matching 'view_name', and if a match is found, it will retrieve the view_id for the first view in the search results.


I hope this helps! Let me know if you have any further questions.

0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Catch is not a function
javascript rpc
Avatar
0
feb. 21
4177
rpc.query doesn't work
javascript rpc odoo
Avatar
Avatar
1
avg. 23
411
How to use RPC query in JavaScript with search method in Odoo 11 / 12?
javascript rpc odoov11
Avatar
Avatar
1
sep. 21
21377
rpc.query function in js not working when I am not logged in Solved
javascript rpc v14
Avatar
Avatar
2
apr. 21
5335
Odoo 10.0, the same procedure of making rpc.query for update data into db? Solved
javascript query rpc
Avatar
1
jun. 18
5242
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now