03-15-2021, 08:23 AM
So this is not working for me. I refactored my webservice call from:
to
But that just created the asset, while I was using a duplicate serial no., which I prohibit in my custom validation function:
PHP Code:
$client->doCreate('Assets', $params);
PHP Code:
$client->doInvoke('CreateWithValidation', array('elementType' => 'Assets', 'element' => json_encode($params)));
PHP Code:
function isUniqueSerial($fieldname, $fieldvalue, $params, $entity) {
global $adb;
$recordid = $entity['record'] == '' ? 0 : $entity['record'];
$r = $adb->query("SELECT vtiger_assets.serialnumber
FROM vtiger_assets
INNER JOIN vtiger_crmentity ON vtiger_assets.assetsid = vtiger_crmentity.crmid
WHERE vtiger_assets.product = {$entity['product']}
AND vtiger_assets.serialnumber = '{$entity['serialnumber']}'
AND vtiger_assets.assetsid != {$recordid}
AND vtiger_crmentity.deleted = 0");
return $adb->num_rows($r) > 0 ? false : true;
}