Client script help with integer field

booher04
Tera Guru

I have a client script setup to pull in data to 2 fields(integer, reference) from 1 field(reference field).  The reference field data is working correctly, however I cannot get the integer field to populate correctly.  I've gotten it to display the sys_id but I can't get the correct value of the field to display automatically.

I have an OnChange client script as follows:

onChane of application_name field.

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

var appName = g_form.getReference('application_name', setInfo);

function setInfo(appName){
g_form.setValue('it_owner',appName.managed_by);

g_form.setValue('app_code',appName.u_app_list);

}
}

 

application_name is a reference to table cmdb_ci_service.  The managed_by is a reference field(it's working how it should) which populates to the it_owner reference field and the u_app_list is an integer on the table cmdb_ci_business_app which is not populating to the app_code field in the catalog item.  I've tried setting the app_code field to a reference variable, look up select box, single line text.. none have worked.  

1 ACCEPTED SOLUTION

try below

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

    getAppData: function() {
        var id = this.getParameter('sysparm_appname');
        var gr = new GlideRecord('cmdb_ci_service');
        if (gr.get(id)) {
            var obj = {};
            obj.managed_by = gr.managed_by.toString();
            obj.u_app_id = gr.u_application_catalog_entry.u_app_id.getDisplayValue();
            return JSON.stringify(obj);
        }
    },

    type: 'appHelper'
});
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ajax = new GlideAjax('appHelper');
    ajax.addParam('sysparm_name', 'getAppData');
    ajax.addParam('sysparm_appname', g_form.getValue('application_name'));
    ajax.getXMLAnswer(function(answer) {
        var answerObj = JSON.parse(answer);
        g_form.setValue('it_owner', answerObj.managed_by);
        g_form.setValue('app_code', answerObj.u_app_id.toString());
    });
}

View solution in original post

12 REPLIES 12

Mike Patel
Tera Sage

try below (app_code fields needs to be single line text)

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

    var appName = g_form.getReference('application_name', setInfo);

    function setInfo(appName) {
        g_form.setValue('it_owner', appName.managed_by);
        g_form.setValue('app_code', appName.u_app_list.toString());
    }
}

Mike thank you for the response.  I tried that and it's just adding in the sys_id to the app code field now.  Also, correction the field is u_app_id not u_app_list.  I updated it below and in the code on my instance as well.

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

var appName = g_form.getReference('application_name', setInfo);

function setInfo(appName) {
g_form.setValue('it_owner', appName.managed_by);
g_form.setValue('app_code', appName.u_app_id.toString());
}
}

Hi,

Did you try:

appName.u_app_id.getDisplayValue()

.getDisplayValue() is not supported in client script