Multiple Cloud Service Accounts with same Account IDs

motsuki17
Tera Guru

I have a requirement that needs to create multiple Cloud Service Account records with the same Account ID (Subscription ID in Azure) but different Discovery Credentials. Basic setup would be like below.

 

Service Principal A (Account ID: XXXX) -> Credential 1 (Client ID: YYYY, ...)

Service Principal B (Account ID: XXXX) -> Credential 2 (Client ID: ZZZZ, ...)

 

The 2 discovery schedules to be created will therefore point to the same Tenant ID and Subscription ID (Account ID) but different Client ID (Application ID). However, when trying to save Service Principal B, it throws an error saying Account ID needs to be unique or duplicate entry.

 

Any ideas on how to deal with my requirement? Thanks.

1 REPLY 1

Yashsvi
Kilo Sage

Hi @motsuki17

try below script:

(function executeRule(current) {
    var existingRecord = new GlideRecord('cmdb_ci_cloud_service_account');
    existingRecord.addQuery('account_id', current.account_id);
    existingRecord.addQuery('discovery_credential', current.discovery_credential);
    existingRecord.query();

    if (existingRecord.next()) {
        gs.addErrorMessage('A record with the same Account ID and Discovery Credential already exists.');
        current.setAbortAction(true); // Prevent saving the current record
    }
})(current);

Thank you, please make helpful if you accept the solution.