Try ERPNext Buy Support Partners Foundation

Webform grid filtering

Dear All.
I created a doctype books.
Added a field to set the level.
Created a webform to display the list of books.
Added a field to the user to specify the level.
I want to filter the webform based on the level of the logged in user.

Can anyone provide with a hint on how to accomplich this functionality?

Thanks.

I managed to get the functionality working by adding the below code to books.py (under web-form folder)
from future import unicode_literals

import frappe

def get_context(context):
context.read_only = 1

def get_list_context(context):
context.get_list = get_book_list

def get_book_list(doctype, txt, filters, limit_start, limit_page_length = 20, order_by=‘modified desc’):
userlevel = get_login_level()
books = frappe.db.sql(""“select * from tabBooks
where level = %s order by creation desc”"", userlevel, as_dict = True)
return books

def get_login_level():
level= frappe.db.sql(""“select level from tabStudent Level
where name1 = %s order by creation desc”"", frappe.session.user)
return level

1 Like