Tom Hanson
Tom Hanson

Reputation: 945

SuiteScript setting "customform" in "beforeLoad"

I am trying to set the form based on a formula in NetSuite. I want the form to use to be determine and loaded before the user accesses the page. The code I am using is a UserEventScript and it is in the beforeLoad function. determineSOForm returns the form internal id.

function beforeLoad(scriptContext) {
    if (scriptContext.type == scriptContext.UserEventType.CREATE) {
        var recNew = scriptContext.newRecord;

        var idCustomer = recNew.getValue('entity');
        var idUser = runtime.getCurrentUser().id;
        var idForm = recNew.getValue('customform');     

        // Set form from user department
        var idNewForm = defaulting.determineSOForm(idUser, null, idCustomer);

        if (idForm != idNewForm) {
            recNew.setValue({
                fieldId : 'customform',
                value : idNewForm
            });

            idForm = idNewForm;
        }
    }
}

Using the Script Debugger I can step through this and it all works fine, but the customform is not set at all. I have read that the customform field cannot be set in the beforeLoad event of a UserEvent Script but now I am lost on how to accomplish this.

Upvotes: 0

Views: 2613

Answers (2)

Samar Haider
Samar Haider

Reputation: 912

Handle this from client script instead of User Event

function pageInit(scriptContext) {
        var recNew = scriptContext.currentRecord;

        var idCustomer = recNew.getValue('entity');
        var idUser = runtime.getCurrentUser().id;
        var idForm = recNew.getValue('customform');     

        // Set form from user department
        var idNewForm = defaulting.determineSOForm(idUser, null, idCustomer);

        if (idForm != idNewForm) {
            recNew.setValue({
                fieldId : 'customform',
                value : idNewForm
            });

            idForm = idNewForm;
        }
}

Upvotes: 1

Praveen Kumar
Praveen Kumar

Reputation: 226

 // Set form from user department
        var idNewForm = defaulting.determineSOForm(idUser, null, idCustomer);
        idNewfrom value is Customform name then
       use below condition
       if (idForm != idNewForm) {
            recNew.setText({
                fieldId : 'customform',
                value : idNewForm
            });

            idForm = idNewForm;
        }
        idNewfrom value is internalid of form then
         use below condition
        if (idForm != idNewForm) {
            recNew.setValue({
                fieldId : 'customform',
                value : idNewForm
            });

            idForm = idNewForm;
        }

Try above code

Upvotes: -1

Related Questions