0

Ive created a button named update in the frontend.

I need to run the function that I wrote in the python file while clicking the button using jquery.

xml:

<t>
<button id="update_health_profile_front" 
        class="btn btn-primary" 
        type="button">Update
</button>
</t>

py:


 @api.multi
    def update_health_profile(self):
        # partner = self.partner_id
        #some_method

js:


$('#update_health_profile_front').click(function(event){
            var rpc = require('web.rpc');
            rpc.query({
            model: 'health.profile',
            method: 'update_health_profile',
        })
        .then(function(result){
            for (i= 0; i< result.length; i++){
                    console.log("result",result[i]);
             }

          },);

Its not working and I don't think this is the right way either, Can anybody share some knowledge?

1
  • Well first you didn't specify the framework you're using (django or Flask). Commented Feb 12, 2021 at 6:07

1 Answer 1

1
+50

Well you can try this, I think it should work.

$('#update_health_profile_front').click(function(event){
            var rpc = require('web.rpc');
            rpc.query({
            model: 'this.name',
            method: 'update_health_profile'
        })
        .then(function(result){
            for (i= 0; i< result.length; i++){
                    console.log("result",result[i]);
             }

          },);

Sign up to request clarification or add additional context in comments.

3 Comments

BUt an error is coming as follows. ids, args = args[0], args[1:] IndexError: list index out of range And please let me know the use of args in the function
@Raihan I have made some edits, pls check it out
@divyesh: i tried to pass the arguments as following args: [health_record_id, health_profile_id], But one argument is only getting, is there any syntax error here? or can you suggest me some?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.