Alert to show dot walk field

Poorva Bhawsar
Mega Sage

Hi Community,

 

On incident form, when user selects business service it should show a popup which contains operational status of the business service which user has selected.

 

Here is my script include.

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

    getCIStatus: function() {
        var ci = this.getParameter('sysparm_ci');
        var gr = new GlideRecord ('cmdb_ci_service');
        gr.addQuery('sys_id', ci);
        gr.query();
        if(gr.next()){
            return gr;
        }
        else{
            return '';
        }
    },

    type: 'TMUtils'
});
 
Here is my client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var ci = g_form.getValue('business_service');
    var ga = new GlideAjax('TMUtils');
    ga.addParam('sysparm_name', 'getCIStatus');
    ga.addParam('sysparm_ci', ci);
    ga.getXML(CallBack);

    function CallBack(response) {
        //var answer = response.responseXML.documentElement.getAttribute("answer");
        //alert(g_form.setDisplayBox('The status of this Business Application is: ' + ci.operational_status));
        alert('The status of this Business Application is: ' + ci.operational_status);
        //alert('HI2' + ci.operational_status);
    }
}
 
But its not showing the alert.
2 ACCEPTED SOLUTIONS

swathisarang98
Giga Sage
Giga Sage

Hi @Poorva Bhawsar ,

 

I found few errors in your script please check below,

1. function Callback corrected to callback

2. You were returning ci.operational_status  which will not work you have to get the values from script include and then capture it in answer variable

3.In client script closing flower bracket  was in wrong place 

 

 

 

 

 

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

    var ci = g_form.getValue('business_service');
    var ga = new GlideAjax('TMUtils');
    ga.addParam('sysparm_name', 'getCIStatus');
    ga.addParam('sysparm_ci', ci);
    ga.getXML(callBack);
}
    function callBack(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        //var userData = answer.split(',');
        // alert('The status of this Business Application is: ' + answer[0]);
            alert('The status of this Business Application is: ' + answer);

    }

 

 

 

 

 

in script include dont return the object instead return the value which you want 

 

 

 

 

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

    getCIStatus: function() {
        var ci = this.getParameter('sysparm_ci');
        var gr = new GlideRecord ('cmdb_ci_service');
        gr.addQuery('sys_id', ci);
        gr.query();
        if(gr.next()){
            gr.operational_status.getDisplayValue();
        }
        else{
            return '';
        }
    },

    type: 'TMUtils'
});

 

 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

    

View solution in original post

Hi @Poorva Bhawsar  in script include could you please try below,

return gr.operational_status.getDisplayValue();

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

6 REPLIES 6

Using this also i am getting the backend value of the operational status. I want to show the display name of the operational status in the alert.

Hi @Poorva Bhawsar  in script include could you please try below,

return gr.operational_status.getDisplayValue();

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang