i want to CSA (servicenow) cerificate with my full name

munukuntlak
Tera Contributor

i want to CSA (servicenow) cerificate with my full name

1 ACCEPTED SOLUTION

Dr Atul G- LNG
Tera Patron
Tera Patron

Is issue still open @munukuntlak 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

12 REPLIES 12

Dr Atul G- LNG
Tera Patron
Tera Patron

Is issue still open @munukuntlak 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

munukuntlak
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;
    
    var requestType = g_form.getValue('request_type');
    var server = g_form.getValue('server');
    
    console.log('=== Maintenance Schedule Type Changed ===');
    console.log('Request Type: ' + requestType);
    console.log('Schedule Type: ' + newValue);
    console.log('Server: ' + server);
    
    // Always hide schedule_name_ref
    g_form.setDisplay('schedule_name_ref', false);
    
    // If no schedule type selected, clear and hide all fields
    if (!newValue || newValue == '') {
        clearAndHideAllFields();
        return;
    }
    
    // Validate server is selected
    if (!server) {
        g_form.addErrorMessage('Please select a Server first');
        g_form.clearValue('maintenance_schedule_type');
        return;
    }
    
    // Call AJAX to get schedule details
    var ga = new GlideAjax('SLAMCatalogUtils');
    ga.addParam('sysparm_name', 'getScheduleDetailsForCatalog');
    ga.addParam('sysparm_schedule_type', newValue);
    ga.addParam('sysparm_server', server);
    ga.addParam('sysparm_request_type', requestType);
    ga.getXMLAnswer(function(answer) {
        if (!answer) {
            g_form.addErrorMessage('Unable to retrieve schedule details');
            // Still show fields even if AJAX fails
            handleNoScheduleFound();
            return;
        }
        
        try {
            var results = JSON.parse(answer);
            console.log('Schedule Details Retrieved:', results);
            
            if (results.error) {
                // M2M record doesn't exist - show fields anyway
                console.log('No M2M record found: ' + results.error);
                g_form.addInfoMessage('No existing schedule found. You can create a new one.');
                handleNoScheduleFound();
                return;
            }
            
            // Store schedule_sys_id in a hidden field for reference qualifier
            if (results.schedule_sys_id) {
                g_form.setValue('hidden_schedule_sys_id', results.schedule_sys_id);
            }
            
            if (requestType == 'add_window') {
                handleAddWindow(results);
            } else if (requestType == 'update_window') {
                handleUpdateWindow(results);
            }
            
            // Make end_time read-only
            g_form.setReadOnly('end_time', true);
            
        } catch (e) {
            console.error('Error parsing response:', e);
            g_form.addErrorMessage('Error processing schedule details');
            // Still show fields even if parsing fails
            handleNoScheduleFound();
        }
    });
    
    // ===== HELPER FUNCTIONS =====
    
    function handleNoScheduleFound() {
        console.log('Handling No Schedule Found - Showing fields anyway');
        
        if (requestType == 'add_window') {
            // Show fields for adding new window even without existing schedule
            
            // Don't populate schedule_name - let user see it's empty
            g_form.clearValue('schedule_name');
            g_form.setReadOnly('schedule_name', false);
            g_form.setDisplay('schedule_name', true);
            g_form.setMandatory('schedule_name', true);
            
            // Show entry details as empty
            g_form.setValue('schedule_entry_details', 'No existing schedule found. This will create a new schedule.');
            g_form.setReadOnly('schedule_entry_details', true);
            g_form.setDisplay('schedule_entry_details', true);
            
            // Hide schedule entry
            g_form.setDisplay('schedule_entry', false);
            g_form.setMandatory('schedule_entry', false);
            g_form.clearValue('schedule_entry');
            
            // Show time zone
            g_form.setDisplay('time_zone', true);
            g_form.setMandatory('time_zone', true);
            g_form.setReadOnly('time_zone', false);
            
            // Set repeat on to weekly
            setRepeatOnToWeekly();
            
            // Show all other fields
            showFieldsForAdd();
            
            // Clear any pre-filled data
            clearEntrySpecificFields();
            
            g_form.addInfoMessage('Fill in the new maintenance window details below');
            
        } else if (requestType == 'update_window') {
            // For update without M2M - show error but allow user to proceed
            g_form.addErrorMessage('No existing schedule found. Please use Add Window instead.');
            clearAndHideAllFields();
        }
    }
    
    function handleAddWindow(data) {
        console.log('Handling Add Window');
        
        // Set Schedule Name (read-only if exists, editable if new)
        if (data.schedule_name) {
            g_form.setValue('schedule_name', data.schedule_name);
            g_form.setReadOnly('schedule_name', true);
            g_form.setDisplay('schedule_name', true);
        } else {
            g_form.clearValue('schedule_name');
            g_form.setReadOnly('schedule_name', false);
            g_form.setDisplay('schedule_name', true);
            g_form.setMandatory('schedule_name', true);
        }
        
        // Set Schedule Entry Details (read-only) - Shows existing entries for reference
        if (data.schedule_entry_text) {
            g_form.setValue('schedule_entry_details', data.schedule_entry_text);
            g_form.setReadOnly('schedule_entry_details', true);
            g_form.setDisplay('schedule_entry_details', true);
        }
        
        // Hide Schedule Entry dropdown (not needed for add)
        g_form.setDisplay('schedule_entry', false);
        g_form.setMandatory('schedule_entry', false);
        g_form.clearValue('schedule_entry');
        
        // Set Time Zone (mandatory)
        if (data.time_zone) {
            g_form.setValue('time_zone', data.time_zone);
        }
        g_form.setMandatory('time_zone', true);
        g_form.setDisplay('time_zone', true);
        g_form.setReadOnly('time_zone', false);
        
        // Set Repeat On to Weekly (read-only)
        setRepeatOnToWeekly();
        
        // Show and make mandatory: Description, Start Time, End Time, Days, Justification
        showFieldsForAdd();
        
        // Clear any pre-filled data
        clearEntrySpecificFields();
        
        g_form.addInfoMessage('Fill in the new maintenance window details below');
    }
    
    function handleUpdateWindow(data) {
        console.log('Handling Update Window');
        
        // Set Schedule Name (read-only)
        if (data.schedule_name) {
            g_form.setValue('schedule_name', data.schedule_name);
            g_form.setReadOnly('schedule_name', true);
            g_form.setDisplay('schedule_name', true);
        }
        
        // Set Schedule Entry Details (read-only) - Shows all entries as reference
        if (data.schedule_entry_text) {
            g_form.setValue('schedule_entry_details', data.schedule_entry_text);
            g_form.setReadOnly('schedule_entry_details', true);
            g_form.setDisplay('schedule_entry_details', true);
        }
        
        // Show Schedule Entry dropdown (mandatory) - filtered by schedule
        g_form.setDisplay('schedule_entry', true);
        g_form.setMandatory('schedule_entry', true);
        g_form.clearValue('schedule_entry');
        
        // Set Time Zone
        if (data.time_zone) {
            g_form.setValue('time_zone', data.time_zone);
        }
        g_form.setMandatory('time_zone', true);
        g_form.setDisplay('time_zone', true);
        g_form.setReadOnly('time_zone', false);
        
        // Set Repeat On to Weekly (read-only)
        setRepeatOnToWeekly();
        
        // Show all fields for update
        showFieldsForUpdate();
        
        // Clear fields until user selects an entry
        clearEntrySpecificFields();
        
        g_form.addInfoMessage('Select a Schedule Entry from the dropdown to update');
    }
    
    function setRepeatOnToWeekly() {
        console.log('Setting Repeat On to Weekly');
        
        // Show the field
        g_form.setDisplay('repeat_on', true);
        
        // Set value to 'weekly'
        g_form.setValue('repeat_on', 'weekly');
        
        // Make it read-only
        g_form.setReadOnly('repeat_on', true);
        
        console.log('Repeat On set to weekly (read-only)');
    }
    
    function showFieldsForAdd() {
        console.log('Showing fields for Add Window');
        
        // Show and make mandatory
        var fields = [
            {name: 'description', mandatory: true, readonly: false},
            {name: 'time_zone', mandatory: true, readonly: false},
            {name: 'start_time', mandatory: true, readonly: false},
            {name: 'end_time', mandatory: true, readonly: true}, // auto-calculated
            {name: 'repeat_on', mandatory: false, readonly: true}, // set to weekly
            {name: 'select_days_of_the_week', mandatory: false, readonly: false},
            {name: 'justification', mandatory: true, readonly: false}
        ];
        
        fields.forEach(function(field) {
            g_form.setDisplay(field.name, true);
            g_form.setMandatory(field.name, field.mandatory);
            g_form.setReadOnly(field.name, field.readonly);
        });
        
        // Show day checkboxes
        var days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
        days.forEach(function(day) {
            g_form.setDisplay(day, true);
        });
    }
    
    function showFieldsForUpdate() {
        console.log('Showing fields for Update Window');
        
        // Same as add
        showFieldsForAdd();
    }
    
    function clearEntrySpecificFields() {
        console.log('Clearing entry specific fields');
        
        g_form.clearValue('description');
        g_form.clearValue('start_time');
        g_form.clearValue('end_time');
        g_form.clearValue('justification');
        
        // Clear day checkboxes
        var days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
        days.forEach(function(day) {
            g_form.setValue(day, false);
        });
        
        console.log('Fields cleared');
    }
    
    function clearAndHideAllFields() {
        console.log('Clearing and hiding all fields');
        
        var allFields = [
            'schedule_name',
            'schedule_entry_details',
            'schedule_entry',
            'description',
            'time_zone',
            'start_time',
            'end_time',
            'repeat_on',
            'select_days_of_the_week',
            'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun',
            'justification'
        ];
        
        allFields.forEach(function(field) {
            g_form.clearValue(field);
            g_form.setDisplay(field, false);
            g_form.setMandatory(field, false);
            g_form.setReadOnly(field, false);
        });
        
        // Always hide schedule_name_ref
        g_form.setDisplay('schedule_name_ref', false);
        
        console.log('All fields cleared and hidden');
    }
}

munukuntlak
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    g_form.setValue('database_server', '');
    g_form.setValue('database_instance', '');
    g_form.setValue('gsi_application_owner', '');
    
    if (newValue == '' || !newValue) {
        console.log('Application cleared - locking fields');
        g_form.setReadOnly('database_server', true);
        g_form.setMandatory('database_server', false);
        g_form.setReadOnly('database_instance', true);
        g_form.setMandatory('database_instance', false);
    } else {
        g_form.setReadOnly('database_server', false);
        g_form.setMandatory('database_server', true);
        g_form.getReference('application_name', function(ref) {
            if (ref && ref.u_gsi_system_manager) {
                console.log('System Manager found: ' + ref.u_gsi_system_manager);
                g_form.setValue('gsi_application_owner', ref.u_gsi_system_manager);
            } else {
                console.log('No System Manager found');
            }
        });
    }
}