Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Script not running in native UI

SHALIKAS
Tera Guru

I have written an onChange client script on server_name variable which is a list collector variable. This script is working in portal, but not in native UI

In native UI even the alert is not coming

 

function onChange(control, oldValue, newValue, isLoading) {
 
    if (isLoading || !newValue) {
        return;
    }

    // Get first selected server from list collector
    var firstServer = newValue.split(',')[0];
alert("firest"+firstServer);
    var ga = new GlideAjax('Coned_fetch_server_details');
    ga.addParam('sysparm_name', 'getServerDetails');
    ga.addParam('sysparm_sys_id', firstServer);

    ga.getXMLAnswer(function(answer) {
alert("Answer = [" + answer + "]");
        if (answer == 'Ansible') {
            g_form.setValue('task_for_automation', 'Yes');
        } else {
            g_form.setValue('task_for_automation', 'No');
        }

    });
}
The script include is
var Coned_fetch_server_details = Class.create();
Coned_fetch_server_details.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getServerDetails: function() {

        var serverId = this.getParameter('sysparm_sys_id');

        gs.info('Server Id = ' + serverId);

        var gr = new GlideRecord('cmdb_ci_server');

        if (gr.get(serverId)) {

            gs.info('Build Source = ' + gr.u_build_source);

            return gr.u_build_source.toString();
        }

        return '';
    },

    type: 'Coned_fetch_server_details'
});

 

6 REPLIES 6

It is not working, tried to add alert statement as well , the alert is also not coming

svirkar420
Kilo Sage

HI @SHALIKAS , If the script is working on the catalogs then it should also work on the native UI as well. 

First make sure you have created a new client script and called the script include appropriately in catalog client script (same script include used for catalogs should be fine).

Can you share the screenshot of the client script form?

If this response helps you mark it as accepted solution and give it a thumbs up 👍. This help me and community to find answers quickly.

Best Regards,

Saurabh V.