Trying to add a Password confirmation field to Sales Invoice

Hi Everyone,

I’ve tried to customize the Sales Invoice form to add a Mandatory Link field on the Sales Invoice form but encountered the following “Challenge” :

  1. Not sure what to put under “options” , I’ve looked around the documentation, I couldn’t find a direct explanation about what to put under Options. I’ve tried some “guesstimates” such as “customer” or “id” and it worked, but for a complete list of reference of link fields from other forms, not sure where to find them. I also noticed that the form’s standard link fields have a “NAME” text box which is uneditable and non-existent when I create my custom link fields , I’m not sure why, can someone explain to me regarding this?

  1. Permission, what should I be writing here if I just wanted this field to appear to “Sales Agent” but not any other user such as “Sales Manager” or “System Manager”?

Your help is greatly appreciated. Thank you.

Anyone mind point me in the right direction? Much thanks appreciated.

As far as Link type is concerned, the options should contain a valid DocType name such as Customer or Supplier. Once you do it, and if you try it on the form, it shows you the dropdown list with the names of current documents made.

this name is the exact name of the attribute in the DB for the doctype which is stored as a table. Let me explain with an example.

This is from Customize Form on Customer Doctype


Now, the same in Database

MariaDB [627c579cf3496713]> desc `tabCustomer`
    -> ;
| Field                                    | Type          | Null | Key | Default  | Extra |
| territory                                | varchar(140)  | YES  |     | NULL     |       |

Hence, name is the label of the field in the table stored in DB.

If you change name, then you are changing the schema of the database, and in case you already have a lot of data, many things could break unless you manually fix them.

But, if you are in developer mode and also if you have all the correct roles, Edit Doctype will let you change the fieldname too but again that is on you adjust other doctypes or reports that may be using this field.

For the non-existent case,

If you are trying to create a new custom field via Customize Form, then this name is not available to you for editing. When you update, you will find that this will be a lowercase version of what you write in Label with spaces replaced by underscores.

You don’t need a password for protecting documents. You can restrict them on the basis of Roles and User Permissions.

You can set permission levels on different fields. These will help you understand this better.

Also, since you are into customizing you should have a look into Custom apps and Fixtures. These will help you preserve your customizations in cases of updates to ERPNext.

If you are on developer mode, don’t use edit doctype on the default documents, but customize form only and export them to your own app.

Hi root13F

Thank you for taking the time to reply in such a detailed way. I’ve finally understood how link fields work. It appears that I have misunderstood some parts of it initially and after trying it out a bit I’m happy to say I can now understand how Link Fields really works. It’s basically a direct reference to DocType only. I was under the impression that the Link field can access child fields under that specific DocType which should be mentioned under the “name” field.

After some experimentation, I found that the system automatically generates the name field when I click update when Customizing form. If i’m Creating new DocType the name field can be edited. However, now I wonder how will I access fields inside a specific DocType, For instance, how would I retrieve the phone number or address of a customer ?

Regarding the password for protecting documents, I know i can protect them using rules and user permissions, told the client the same as well, but clients will always be clients, they insist to request user to enter their password to complete the action… so i’m trying to find out sample source to perform this…

Retrieving a value from a doctype is easy and can be done via a number of ways, given that you know how to locate that value:-

In Python :

To get single value

customer_name = frappe.get_value("Customer", self.customer, "customer_name")

To get complete document

this_customer = frappe.get_doc("Customer", self.customer)

Then you can manipulate values like this this_customer.disabled = 1 and save it too. (don’t forget frappe.db.commit() after that)

For details like Address and Contact, the documents are linked via a Dynamic Link which is a child table which stores these cross references so you need to find the correct link for that.

I recommend that whenever possible check examples of such kind in the code itself and you will learn more. So, we have to do it the hard way.

Here’s an example:

#Step 1 : Retrieve the correct reference to the Customer's Contact
                if customer:
                    dyn_link = frappe.get_all(
                        "Dynamic Link", filters={"link_doctype": "Customer", "link_name": customer, "parenttype": "Contact"}, fields=["parent"])
#Step 2 : Retrieve the value from the DocType
                    for contact in dyn_link:
                        mobile_no = frappe.get_value(
                            'Contact', contact.parent, 'mobile_no')

Hmm. I think you should check out how users are being authenticated.

Hmm. I think you should check out how users are being authenticated.

Yup, it’s so easy , I found the code on the Doctype : Company .


<— Just raise the above and if the authentication failed user will be booted back to website.

This thread can be closed now :slight_smile: