Discovery did not triggered or execute after created through Business Rule

HARSHIT7
Kilo Expert

I have created Business Rule on table Cloud Service Account and it does create new Discovery Schedule. When I click on "Discover Now" it shows started and did not processed and completed.
/////////////////////Business Rule//////////////////////////

(function executeRule(current, previous /*null when async*/ ) {
    var sch_name = "Cloud Service Account - " + current.name;
    var scheduleData = {
        runType: 'daily',
        runPeriod: 'daily',
        runPeriodType: 'day',
        acceleratorConfig: {
            midServerList: ['94c3de791b7fcc10a6606537bc4bcb8a', '8aa1b3471ba96c549e788661ec4bcba7', 'd74f8c9b1ba1a094b5fbdceddc4bcb83'], // Replace with your MID Server sys_id
            cloud_api_throttle: 'moderate',
        },
        is_Discover_VM: false,
        ciSchedule: {
            name: sch_name,
            runType: 'daily',
            runPeriod: 'daily',
            runPeriodType: 'day'
        },
        ldcConfig: {
            create_new_ldc: true,
            azure_region_set: ['canada central', 'canada east']
        },
        name: sch_name,
        active: true,
        cloud_provider: 'AZURE',
        schedule: 'Run Daily', // can be a sys_id of a schedule OR a schedule string run daily
        sys_class_name: '',
        pattern: ''
    };
    var cloudDiscoveryScheduleConfig = new CloudDiscoveryScheduleConfig();
    var result = cloudDiscoveryScheduleConfig._createCloudSchedule(scheduleData);
    if (result.success) {
        gs.info("Cloud Discovery Schedule created: " + sch_name + " -- " + result.scheduleId);
        // Trigger the discovery process immediately
        discoverNow(result.scheduleId);
    } else {
        gs.error("Error creating Cloud Discovery: " + sch_name + " -- " + result.message);
    }
    function discoverNow(scheduleGr) {
        // Assuming that the scheduleGr is valid, we proceed
        if (!isValidDiscoverySchedule(scheduleGr)) {
            return "";
        }
        // Trigger this discovery...
        var jobSysId = SncTriggerSynchronizer.executeNow(scheduleGr);
        // Get the scheduler created discovery status, and update it with proper description and source
        var status = new GlideRecord('discovery_status');
        status.addQuery('scheduler_job', jobSysId);
        var timeoutSeconds = gs.getProperty('glide.discovery.discover_now_timeout', 10);
        // Searches for a max of timeoutSeconds seconds.
        for (var attempts = 0; attempts < timeoutSeconds * 4; attempts++) {
            status.query();
            if (status.hasNext())
                break;
            gs.sleep(250);
        }
        if (!status.next()) {
            return null;
        }
        //status.setValue('description', 'Discover Now');
        status.setValue('description', 'Scheduled');
        status.setValue('source', 'Discover_now_schedule');
        status.update();
    }
    function isValidDiscoverySchedule(scheduleGr) {
        // Implement the logic to validate the discovery schedule
        // Return true if valid, otherwise false
        return true; // Placeholder: replace with actual validation logic
    }
})(current, previous);

Please advise what is issue in above my logic.
3 REPLIES 3

Kieran Anson
Kilo Patron

Is there a reason you're not using the cloud discovery dashboard to create these schedules and other related records?

 

What's the condition on your business rule?

Because everyday they are adding and removing the subscriptions on other azure side. So it's hard to maintain the subscription details which are created as new and remove. Also, creation of manually using the dashboard it's easy but for implementation process is too lengthy where I work. So we are trying to automate this process so we do not need to monitor everyday. Also there is no condition in the BR's. 

Have you also create a custom "Discover Now" UI action, as that UI action is not available on the Cloud Service Account table by default?