Using Typescript and SuiteScript 2.1, write a func...
# ask-stanley-ai
d
Using Typescript and SuiteScript 2.1, write a function that is shareable between a client Script pageInt and a User Event BeforeLoad to show/hide fields
c
AI generated answer (using internal Slack threads):
Based on the conversations, you can use SuiteScript 2.1 and TypeScript to create a function that can be shared between a client Script pageInit and a User Event BeforeLoad to show/hide fields. Here is a sample code:
Copy code
typescript
import { EntryPoints } from 'N/types';
import * as serverWidget from 'N/ui/serverWidget';

export function beforeLoad(context: EntryPoints.UserEvent.beforeLoadContext) {
    if (context.type !== context.UserEventType.CREATE) {
        return;
    }

    const form = context.form;
    const field = form.getField({
        id: 'custpage_field_to_update'
    });

    if (field) {
        field.updateDisplayType({
            displayType: serverWidget.FieldDisplayType.HIDDEN
        });
    }
}

export function pageInit(context: EntryPoints.Client.pageInitContext) {
    const record = context.currentRecord;
    const field = record.getField({
        fieldId: 'custpage_field_to_update'
    });

    if (field) {
        field.isDisplay = true;
    }
}
In the
beforeLoad
function, we are hiding the field by setting its display type to
HIDDEN
using the
updateDisplayType
method. This function will be executed when the form is being loaded. In the
pageInit
function, we are showing the field by setting its
isDisplay
property to
true
. This function will be executed when the page is initialized. Please note that the field must start off normally displayed. If it starts off hidden, you can't change it to be visible using SuiteScript. Also, you need to check the permission level of the field. ****** 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.845864356
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.845313787
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.833444357
Please provide your feedback on this answer.