Yes  totalrecords decalred.

Updated the code like below in controller: But still throwing issue

Controller code:
@auth.requires_login()
def update_timesheet():

    totalrecords=0;
    rows = db((db.ActivityMapping.org_id==db.Organization.id)&
    (db.ActivityMapping.resource_id==db.auth_user.id)&
    (db.ActivityMapping.solution_id==db.Solution.id)&
    (db.ActivityMapping.activity_id==db.Activity.id)&

(db.auth_user.id==auth.user.id)&(db.ActivityMapping.activity_date==request.vars.activity_date)
             
).select(db.auth_user.first_name,db.Organization.short_name,db.Solution.solution_code,db.Activity.activity_name,db.ActivityMapping.effort,db.ActivityMapping.activity_date)

    for u in request.vars.org_id:
        totalrecords=totalrecords+1


    if totalrecords == 1:
        
rows.update_record(resource_id=auth.user.id,org_id=int(request.vars.org_id),solution_id=int(request.vars.solution_id),activity_id=int(request.vars.activity_id),effort=int(request.vars.effort))
    elif totalrecords>1:
        for m in request.vars.org_id:
            #e= e+ ' org: ' + str(m) + ' act: '+
str(request.vars.activity_id[i]) + ' soln: ' +
str(request.vars.solution_id[i]) +' effort: '+str(request.vars.effort)
            
rows.update(resource_id=auth.user.id,org_id=int(m),solution_id=int(request.vars.solution_id[i]),activity_id=int(request.vars.activity_id[i]),effort=int(request.vars.effort[i]))
            i=i+1

    return locals()
_________________________________________

View Code:
ajax('{{=URL('update_timesheet')}}',['org_id','solution_id','activity_id','effort','activity_date'],'target');
___________________

Model code:
db.define_table('ActivityMapping',
                Field('mapping_id'),
                Field('resource_id',db.auth_user),
                Field('org_id',db.Organization),
                Field('solution_id',db.Solution),
                Field('activity_id',db.Activity),
                Field('activity_date','datetime', requires=IS_DATE()),
                Field('effort')
                )

On Wed, Aug 10, 2016 at 9:52 AM, Kiran Subbaraman
<[email protected]> wrote:
> In the controller, is your code entering the `if` checks? And am guessing
> the totalrecords is initialized before you do a
> `totalrecords=totalrecords+1`?
> Noticed that you are using `update_record` and `update` in your code. Do
> take a look at this:
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=update_record#update_record
>
> ________________________________________
> Kiran Subbaraman
> http://subbaraman.wordpress.com/about/
>
> On Tue, 09-08-2016 10:43 PM, madhu nomula wrote:
>
> Hi ,
>
> In Web2 py tool
>
> need sample code to update db table(module) from View value to --->
> Controller code for updating:
>
>
> View code
> :
> ajax('{{=URL('update_data')}}',['org_id','solution_id','activity_id','effort'],'target');
>
>
> Controller code:
>
> def update_data():
>
>     for u in request.vars.org_id:
>         totalrecords=totalrecords+1
>
>
>     if totalrecords == 1:
>
> db.ActivityMapping.update_record(resource_id=auth.user.id,org_id=int(request.vars.org_id),solution_id=int(request.vars.solution_id),activity_id=int(request.vars.activity_id),effort=int(request.vars.effort))
>     elif totalrecords>1:
>         for m in request.vars.org_id:
>             #e= e+ ' org: ' + str(m) + ' act: '+
> str(request.vars.activity_id[i]) + ' soln: ' +
> str(request.vars.solution_id[i]) +' effort: '+str(request.vars.effort)
>
> db.AM.update(resource_id=auth.user.id,org_id=int(m),solution_id=int(request.vars.solution_id[i]),activity_id=int(request.vars.activity_id[i]),effort=int(request.vars.effort[i]))
>             i=i+1
>
>     return locals()
>
>
> Facing issue with above code,.
>
> Regards,
> MC
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to