What is the best way to add a field at the very TO...
# suitescript
j
What is the best way to add a field at the very TOP of a form (top of page) for a standard record using UserEvent? I know how to add a field, just not sure how to get it to show FIRST.
m
Copy code
function beforeLoad({ form }) {
        var newField = form.addField({
            id: 'custpage_test',
            label: 'CustPage Test',
            type: ui.FieldType.TEXT
        });
        
        form.insertField({
            field: newField,
            nextfield: 'entityid'
        });
    }
j
I’m not convinced all records have
entityid
m
That was an example. Depending on how many record types you need this to run on, you could maintain a mapping object of transaction type to first field name and use that to decide which field it should be put before. It might be too cumbersome if you have a lot of records. You could also store the map in a script parameter to make it easier to update in the future.
Copy code
const { type } = context.newRecord;

const fieldMap = {
  employee: 'entityid',
  salesorder: 'customform'
};

const firstField = fieldMap[type] || 'entityid';

form.insertField({
  field: newField,
  nextfield: firstField
});
j
I want to have this on all records. Like ALL all.
I thought maybe there was a simple way to just be like “put this first”
m
Sorry, I don't see anything that would be that predictable.