Skip to content

gsOnAfterImportValue

Triggered after importing values. Here we can perform some action after the import.

Available variables:

NameDescription
successImport status for each value
modeImport mode: new||upd||null
objectImport object
targetObjectThe target object that was created or updated
valueValues for importing a single object

modUser

If the user was created, send them an email.

php
if ($modx->event->name === 'gsOnAfterImportValue') {
    if ($object->model_class === 'modUser') {
        if ($mode === 'new') {
            $password = $targetObject->generatePassword();
            $targetObject->set('password', $password);
            $targetObject->save();
            
            $message = "You login: $targetObject->username <br> You password: $password";
            $name = $targetObject->fullname ?? $targetObject->username;
            $targetObject->sendEmail($message, [
                'subject' => "Hello, $name"
            ]);
        }
    }
}

modResource

For created resources, update the publication date (publishedon).

php
if ($modx->event->name === 'gsOnAfterImportValue') {
    if ($object->model_class === 'modResource') {
        if ($mode === 'new') {
            $targetObject->set('publishedon', time());
            $targetObject->save();
        }
    }
}

msProduct

Mark the "new" checkbox for new products.

php
if ($modx->event->name === 'gsOnAfterImportValue') {
    if ($object->model_class === 'msProduct') {
        if ($mode === 'new') {
            $targetObject->set('new', 1);
            $targetObject->save();
        }
    }
}

© GoogleSheets 2019-present