Update data in an existing DocType record through a web form

Example Scenario:

I have added some custom fields, such as Phone Number, Documents (Child Table), Address, etc to the Job Applicant Doctype. I want to capture these details from applicants through a Web Form since they do not have access to the Desk. Additionally, I want to update these details in the existing Job Applicant Doctype.

Is there a way to achieve this?

1 Like

Get all fields in the webform and check it.

Then you can easily update the existing data without using the desk.

1 Like

I don’t wanna get custom fields in Current webform I want to update existing record

My Case

  1. HR Manager will create a Job Applicant record (e.g. HR-JP-******)
  2. If an applicant is shortlisted then in same record(HR-JP-***) I want to collect applicant details(Phone Number, Documents (Child Table), Address, etc) for which I have created a new web form with fields Phone Number, Documents (Child Table), Address, etc
1 Like

Not sure, but you can try with a server script.

1 Like

for now I have applied my custom logic in validate function and it is working as expected, but while going through web_form.py code I’ve found something related to update existing record.

But I haven’t found any steps to implement this.

1 Like

I’m suggesting you try with a normal server script. When the web form is saved, it will basically save the data to a doctype. So, when the doctype is saved, you can update the data using doc_events. Give it a try. (Not tested, but maybe it should work.)

1 Like

If I will do in after save event then it will create a new record in doctype and I don’t want to create a new record I want to update the data in the existing record :sweat_smile: .

1 Like

same thing you can do with doc_events.

have you tried?
How will you know without trying?

You have to apply logic and only you know where I want to update so think a little.

1 Like

I think you didn’t understand my case. I have already tried using the “after save” event; it is creating a new record through the webform. I don’t want to create a new record; I want to update an existing record, which the HR Manager created.

1 Like

Hello @ejaaz , have you solved this issue? I’m doing the similar task on Employee DocType. Can you share me the solution?

1 Like

Hi @ducminhgd
I have made a server call in the validate method in js and saved the form data manually by passing the unique name in the form. I took code from this function, modified it a little, and after saving the data, returned false in the validate function.

2 Likes

@ejaaz - Is it possible for a guest user to update the existing doc through Web Form without logging in ?

Tried doing it via below JS, but still a new doc get created.

frappe.web_form.validate = async () => {
    let mobile_no = frappe.web_form.get_value('mobile_no');
    if (!mobile_no) return;

    let digits = mobile_no.replace(/\D/g, '');
    let tail = digits.slice(-8);

    try {
        const r = await frappe.call({
            method: 'get_existing_lead_name',
            args: { mobile_no: tail }
        });

        console.log("----------", r.message); 

        if (r.message) {
            frappe.web_form.set_value('name', r.message);
        }
    } catch (e) {
        return false;
    }
};