Editable field only in a new record

Leandro Oliveir
Tera Contributor

I need a reference field (from a custom table) to be editable on the form only in a new record. After creating this record, the field must be read-only. I tried to do this through a Business Rule but it didn't work. What other way can I solve this problem?

1 ACCEPTED SOLUTION

Manmohan K
Tera Sage

Hi @Leandro Oliveir 

 

You can create a on load client script like below

(Modify below script to add backend name of your reference field in place of field_name)

 

function onLoad() {
  var isNewRecord = g_form.isNewRecord(); // Check if the record is new

  if (isNewRecord) {
    g_form.setReadOnly('field_name', false); // Make the field editable
  } else {
    g_form.setReadOnly('field_name', true); // Make the field read-only
  }
}

  

View solution in original post

4 REPLIES 4

Manmohan K
Tera Sage

Hi @Leandro Oliveir 

 

You can create a on load client script like below

(Modify below script to add backend name of your reference field in place of field_name)

 

function onLoad() {
  var isNewRecord = g_form.isNewRecord(); // Check if the record is new

  if (isNewRecord) {
    g_form.setReadOnly('field_name', false); // Make the field editable
  } else {
    g_form.setReadOnly('field_name', true); // Make the field read-only
  }
}

  

Hi @Manmohan K , the client script works. Thanks for the help!

Sohithanjan G
Kilo Sage

Hi @Leandro Oliveir 

 

The recommended way is to create a write ACL on that field with this custom script in advanced part of ACL

 

answer = current.isNewRecord()

 

 

Please mark the answer as helpful if it meets your requirement. If you write client script, it can be still edited in list view and with some browser manipulation.

 

 

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)

Thanks , This is the best approach.