how to lock some fields after save record
# ask-stanley-ai
t
how to lock some fields after save record
c
AI generated answer (using internal Slack threads):
To lock some fields after saving a record, you can use a combination of workflows and client scripts. Here are the steps you can follow: 1. Create a workflow that triggers on the 'After Record Submit' event. 2. Add a 'Set Field Display Type' action to the workflow. This action will allow you to set the display type of the field you want to lock. 3. Set the display type to 'Inline' or 'Disabled'. This will make the field uneditable. Here is a sample workflow action:
Copy code
javascript
{
  "recordType": "customrecord_my_custom_record",
  "triggerType": "AFTER_RECORD_SUBMIT",
  "actions": [
    {
      "actionType": "SET_FIELD_DISPLAY_TYPE",
      "fields": [
        {
          "fieldId": "custrecord_my_custom_field",
          "displayType": "DISABLED"
        }
      ]
    }
  ]
}
Alternatively, you can also use a client script to lock the field on the 'Page Init' event. Here is a sample client script:
Copy code
javascript
function pageInit(scriptContext) {
  var currentRecord = scriptContext.currentRecord;
  currentRecord.getField({fieldId: 'custrecord_my_custom_field'}).isDisabled = true;
}
Please note that if the record is locked by a workflow, you can change the context settings of the 'Lock Record' action to not include your script type or set it to 'User Interface'. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815459609
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.811790824
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.810137749
Please provide your feedback on this answer.