Service Catalog - Lookup Select Box - Script Include - Catalog Clent Script

Mark Lanning
Tera Guru

Asking for some help please.

Want to take the selected item from the Lookup Select Box to populate the Request with information from the cmdb_ci_computer table. - I am either getting nothing or getting undefined as returned value.

 

Catalog Client Script

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

    //Type appropriate comment here, and begin script below

    var gajax = new GlideAjax('demoDetailsUtil');
    gajax.addParam('sysparm_name', 'getModalityDetails');
    gajax.addParam('sysparm_name', newValue);
    gajax.getXML(setModalityDetails);
   
    function setModalityDetails(serverResponse) {
        var cc = serverResponse.responseXML.documentElement.getAttribute("answer");

        g_form.setValue('modality_ae_title', cc.u_modality_ae_title);
        g_form.setValue('modality_station_name', cc.u_modality_station_name);
        g_form.setValue('modality_port', cc.u_modality_port);
 
Script Include
var demoDetailsUtil = Class.create();
demoDetailsUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getModalityDetails: function() {
        var name = this.getParameter('sysparm_name');
        var gr = new GlideRecord('cmdb_ci');
        gr.addQuery('variables.select_the_available_demo_configuration', name);
        gr.query();

        if (gr.next()) {
            return gr.sys_id;

        } else {
            return '';
        }

    },
    type: 'demoDetailsUtil'
});

 

 

4 REPLIES 4

Harsh Vardhan
Giga Patron

Hi @Mark Lanning  Have you tried to add log in script include to check if client side data going into script include ?

Also sysparm_name parameter reserved for function name, so please change it to different name , eg:  sysparm_id

eg: 

var gajax = new GlideAjax('demoDetailsUtil');
    gajax.addParam('sysparm_name', 'getModalityDetails');
    gajax.addParam('sysparm_id', newValue);
    gajax.getXML(setModalityDetails);

 

Please try and let me know if it does not work, also add logs. 

 

Thanks,

Harsh

 

Mark Lanning
Tera Guru
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var demo = g_form.getValue('select_the_available_demo_configuration'); // variable value

    g_form.setValue('modality_ae_title', demo.u_modality_ae_title);
    g_form.setValue('modality_station_name', demo.u_modality_station_name);
    g_form.setValue('modality_port', demo.u_modality_port);
    g_form.setValue('network_wired_ip_address', demo.ip_address);
    g_form.setValue('network_wired_mac_address', demo.mac_address);

This will return undefined. Adding logs to the previous attempt with script include and client script did not register.

 

James Chun
Kilo Patron

Hi @Mark Lanning,

 

Had a quick look at the script and the obvious ones that I can see are the following:

 

Change the param name in the Client script:

 

   gajax.addParam('sysparm_name', 'getModalityDetails');
    gajax.addParam('sysparm_name', newValue);

 

 You would need to change the second param to something other than sysparm_name. Also, make sure you update the Scrtip Include with the new param name as well.

 

Are you sure the CI query is correct?

variables.select_the_available_demo_configuration
There shouldn't be any 'variable' object in CI records.

 

 

Cheers

Sorry, still not getting this, is it because I am using a Lookup Select Box?

 

Script Include

var getDemoinfo = Class.create();
getDemoinfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {

 get_demo: function() {
        var demo = this.getParameter('select_the_available_demo_configuration');
        var gr = new GlideRecord("cmdb_ci_computer");
        gr.addQuery("sys_id", demo);
        gr.query();
        if (gr.next()) {
          				return;
            }        

    },
    type: 'getDemoinfo'
});

Catalog Client Script

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

    //Type appropriate comment here, and begin script below
    var gaDemo = new GlideAjax('getDemoinfo');
    gaDemo.addParam('sysparm_name', 'get_demo');
    gaDemo.addParam('sysparm_fields', '["u_modality_ae_title","u_modality_station_name","u_modality_port","ip_address","mac_address","u_modality_subnet_mask","u_modality_gateway,"u_wireless_ip","u_wireless_mac_address","u_wireless_subnet_mask","u_wireless_gateway","u_modality_user","u_modality_password","u_ssid","u_security_mode","u_wpa_mode","u_authentication_type","u_one_logical_name","u_one_ae_title","u_one_ip_address","u_one_port","u_two_logical_name","u_two_ae_title","u_two_ip_address","u_two_port","u_three_logical_name","u_three_ae_title","u_three_ip_address","u_three_port","u_four_logical_name","u_four_ae_title","u_four_ip_address","u_four_port"]');
    gaDemo.getXML(_handleResponse);

    function _handleResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");

        //var demo = g_form.getValue('select_the_available_demo_configuration'); // variable value


        g_form.setValue('modality_ae_title', answer.u_modality_ae_title);
        g_form.setValue('modality_station_name', answer.u_modality_station_name);
        g_form.setValue('modality_port', answer.u_modality_port);
        g_form.setValue('network_wired_ip_address', answer.ip_address);