I’ve created a “My Profile” web form referencing the Contact DocType with this settings:
I’m trying to create a page where the website user can update his or her information in the related Contact DocType. The user was created through the “Invite as User” button in the Contact page. One reason why the Contact DocType is used, is because adding of fields in the User DocType is restricted. Here’s the code in the my_profile.py:
from __future__ import unicode_literals import frappe import json import datetime from frappe.contacts.doctype.contact.contact import get_contact_name def default(o): if isinstance(o, (datetime.date, datetime.datetime)): return o.isoformat() def get_context(context): # frappe.clear_cache(doctype="Contact") contact_name = get_contact_name(frappe.session.user) # frappe.throw(contact_name) contact = frappe.get_doc('Contact', contact_name) # frappe.throw("hmmm") frappe.throw(json.dumps( contact, sort_keys=True, indent=1, default=default) ) context.doc = contact frappe.form_dict.new = 0 return context
I am able to frappe.throw the contact_name properly (it returns the correct value) and I could also access any Contact record associated with the user by manually changing the url to http://site/my-profile?name=[name] replacing the [name] with any existing name of Contact.
Anything else that I need to do to make the frappe.get_doc work? I’ve also tried the get_cached_doc method and it is returning null too. I’ve also tried the bench --site all clear-cache.
For reference, I followed this guide.
I think this one’s related to this issue: Mapping webform to doctype, get_context not working
Any suggestions are greatly appreciated!