Saturday, December 1, 2018

Set the Password on Customer Records via SuiteScript with Before Record Submit function and Suitelet

 

Setting the password and password2 for a customer via SuiteScript must be done via Client Side Script on the On Save function, After Record Submit or Scheduled Script.

Doing this using a Server Side Script Before Submit and a Suitelet will return the error below even if the password you are setting is less than 16 characters:

EXCEEDED_MAX_FIELD_LENGTH
The field password contained more than the maximum number ( 16 ) of characters allowed.

This is because the characters are already being encrypted on the server side.

A sample snippet of the Client Side Script is shown below:

function setPassOS(){

    nlapiSetFieldValue('giveaccess', 'T');
    nlapiSetFieldValue('password', 'DfltPsswrd');
    nlapiSetFieldValue('password2', 'DfltPsswrd');
    return true;
}

A sample snippet of the User Event Script After Submit or Scheduled Script is shown below:

function setPW_scheduled(){
    var rec = nlapiLoadRecord('customer','261');
    rec.setFieldValue('giveaccess', 'T');
    rec.setFieldValue('password', 'Password');
    rec.setFieldValue('password2', 'Password');
    var pass = rec.getFieldValue('password');
    nlapiLogExecution('DEBUG',pass);
    nlapiSubmitRecord(rec,true);
}

No comments:

Post a Comment