Wednesday, January 23, 2019

PHP Toolkit New Version (2012.2 and Later) > Change User Password

Below is a sample code to change the password of a user using the 2012.2 PHP Toolkit:

<?php
function passwordreset($id,$newpass){
 $service = new NetSuiteService();

 $emp = new Employee();
 $emp->internalId = $id;
 $emp->password = $newpass;
 $emp->password2 = $newpass;

 $updateRequest = new UpdateRequest();
 $updateRequest->record = $emp;
 $updateResponse = $service->update($updateRequest);
 if (!$updateResponse->writeResponse->status->isSuccess) {
        echo "UPDATE ERROR";
 } else {
  echo "UPDATE SUCCESS ID " . $updateResponse->writeResponse->baseRef->internalId."\n";
    }
}
?>
<form  id="form" name="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 <input type="password" id="empid" name="empid" value="" />&nbsp;
 <input type="password" id="emppass" name="emppass" value="" />&nbsp;
 <input type="submit" id="searchsubmit" name="searchsubmit" value="Save" />
</form>
<?php
 if(isset($_POST['searchsubmit'])){if($_POST['searchsubmit'] == "Save"){
 if(isset($_POST['emppass'])){
  passwordreset($_POST['empid'],$_POST['emppass']);
 }     
 }}
?>

No comments:

Post a Comment