How do I display the name of a parent record on th...
# ask-stanley-ai
c
How do I display the name of a parent record on the child form - instead of the ID?
c
AI generated answer (using internal Slack threads):
To display the name of a parent record on the child form instead of the ID, you can use a combination of SuiteScript and SuiteFlow. Here's a general approach: 1. Create a new field on the child record to hold the parent record's name. This field should be a free-form text field. 2. Create a User Event script that triggers on the 'beforeSubmit' event of the parent record. This script should fetch the desired name or combination of fields from the parent record and store it in the new field you created on the child record. 3. Deploy this script on the parent record. 4. Create a workflow on the child record that triggers on the 'beforeLoad' event. This workflow should copy the value from the new field you created (which now holds the parent's name) to the field that is displayed on the child form. Here's a pseudo-code example of what the User Event script might look like:
Copy code
javascript
function beforeSubmit(scriptContext) {
    if (scriptContext.type !== scriptContext.UserEventType.CREATE && scriptContext.type !== scriptContext.UserEventType.EDIT)
        return;

    var parentRecord = scriptContext.newRecord;
    var parentName = parentRecord.getValue('fieldname'); // replace 'fieldname' with the actual field name

    var childRecordId = parentRecord.getValue('childrecordfieldname'); // replace 'childrecordfieldname' with the actual field name
    var childRecord = record.load({
        type: 'customrecord_child', // replace 'customrecord_child' with the actual child record type
        id: childRecordId
    });

    childRecord.setValue('newfieldname', parentName); // replace 'newfieldname' with the actual new field name
    childRecord.save();
}
Remember to replace the placeholders in the pseudo-code with your actual field and record names. ****** 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.832043707
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815969884
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815582454
Please provide your feedback on this answer.