Try ERPNext Buy Support Partners Foundation

Mapping webform to doctype, get_context not working

I’ve created a DocType, Candidate to allow users to update their Candidate Profiles from the portal.

Following this great tutorial, Webinar on Frappe portals, everything works fine up until auto-populating of the web form. 10:00

To populate a webform with values of a user’s document, you need to add the following to the webform.py, in my case candidate_profile.py:

def get_context(context):
	candidate = frappe.get_doc("Candidate", {'email_id': frappe.session.user})
	context.doc = candidate
	frappe.form_dict.new = 0
	frappe.form_dict.name = candidate.name

The form, located on http://site1.local:8000/candidate-profile is then supposed to auto-populate with information from John Doe’s candidate profile.

However, the form remains blank on refresh.

It is not a permissions issue, as John Doe can view (but not update) his profile on this url:
http://site1.local:8000/candidate-profile?name=john@doe.co

Any ideas?

1 Like

I’ve tried it with the existing Patient doctype which uses the personal-details webform, and it also does not auto-populate. Do you think the get_context function does not execute for some reason?

1 Like

Is it really frappe.form_dict.name = candidate.name, not frappe.form_dict.first_name = candidate.name?

The form has both a name and first_name field, and neither works. But thanks for the comment.

I’ve found a workaround (or maybe this is how to connect web forms with docs):

  1. Create a portal page

  2. Create a button to redirect to the webform (in my case candidate-profile) quering the docname (in my case the user’s email):

<button class="btn btn-default btn-xs btn-info">
<a href="/candidate-profile?name={{ frappe.session.user }}"> Update Profile </a>
</button>

Hello.

I have run into the same issue following the Youtube tutorial. Anyone else have other suggestions? I don’t think one should add a query string to get the right context, since that should have been the purpose of setting the context in the get_context method. This way, a user may freely access other records (correct me if I’m wrong) by changing the URL if they know the email. This must work as it is necessary in creating any customizations in the portal. Help… :sob:

Thank you!