Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Having problem with onLoad client script

Abhijit Das7
Tera Expert

Hi everyone,

I am working on onLoad Client script and script include . I am facing problem that I am not getting back response from script include . I have placed alert(res) , and it is giving null value.

 

Script Include:
var DisplayModelName = Class.create();
DisplayModelName.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getName: function() {

        var url_sysID = this.getParameter('sysparm_id');
		gs.info("sys id of url " +url_sysID);
		
	

        var table = new GlideRecordSecure('x_care3_carear_fsm_instruct_experience');
        table.addQuery('sys_id', url_sysID);
        table.query();
        if (table.next()) {
             var name = table.getValue('instruct_model_name');
			
			gs.info("name of model" +name);
        }

        return name;

    },

    type: 'DisplayModelName'
});

.

Client Script :
function onLoad() {
    //Type appropriate comment here, and begin script below
    var doc;
    var iframe = top.document.getElementById('gsft_main'); //main iframe
    var listIframe = iframe ? iframe.contentWindow.document.querySelector('[name=gsft_list_form_pane]') : null; //split view iframe
    //listIframe is null if iframe is null (when open record outside of frame, ie. not within nav_to) OR can not be determined by the selector above (for when the record is opened in regular form view, no split view)
    if (listIframe == null) {
        doc = iframe ? iframe.contentWindow.document : top.document;
    } else
        doc = listIframe.contentWindow.document; //listIframe exists when record is opened in split view, set doc to listIframe.contentWindow.document
    var element = doc.getElementById('wm_task.x_care3_carear_fsm_instruct_experience_value.instruct_model_url_link');
    alert(g_form.getValue('x_care3_carear_fsm_instruct_experience_value'));
    if (element)
        element = g_form.getValue('x_care3_carear_fsm_instruct_experience_value'); //set text of URL

    var ga = new GlideAjax('x_care3_carear_fsm.DisplayModelName');
    ga.addParam('sysparm_name', 'getName');
    ga.addParam('sysparm_id', element);
    ga.getXMLAnswer(modelName);

    function modelName(response) {
        var res = response.reponseXML.documentElement.getAttribute('answer');
        alert(res);
       



    }




}
7 REPLIES 7

Hi Virendra,

What is the field type of 'instruct_model_name' is this a String field?

Ethan

Vamsi Sreenivas
Tera Guru

Hi @Virendra Dwivedi / @Virendra Dwivedi ,

 

Have you tried using just getXML() instead of getXMLAnswer()?

 

Regards,

Vamsi S

Hi @Vamsi Sreenivas 

Yes . I have tried that also.