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

Community Alums
Not applicable

I have already used the getreference function but if use this then it will not show the name of the status it will only show the value. For that i need to use script include and call that script include inside client script.

piyushsain
Tera Guru
Tera Guru

Hi @Poorva Bhawsar 

Please use this in alert:

alert('The status of this Business Application is: ' + g_form.getValue('business_service.operational_status'));

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

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