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.

Show Field Message below the user field

Revathi12
Tera Contributor

Hi Team,

 

I have variable user which is reference to sys_user and I need to populate the user ID of the user as field message. I tried with showfieldMessage but no luck. Can anyone help me on this.

 

Thanks

1 ACCEPTED SOLUTION

@Revathi12 remove single inverted comma from ans

 

 

g_form.showFieldMsg('user', ans , 'info');

 

 

Try with the above

 

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

Regards,

Swathi Sarang

View solution in original post

11 REPLIES 11

Hi @swathisarang98 

 

I have updated the code, but still I can see still its printing as ans.

 

CS :-

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
var ga = new GlideAjax('TestUserID');
ga.addParam('sysparm_name', 'getUserID');
ga.addParam('sysparm_userID', newValue);
ga.getXML(getResults);


}

function getResults(response) {
   
    var ans = response.responseXML.documentElement.getAttribute("answer");
    alert(ans);

    if (ans != '') {
        g_form.showFieldMsg('user','ans', 'info');
       
    }






   
// alert("AD");
// var gr = new GlideRecord('sys_user');
// gr.addQuery('sys_id', newValue);
// gr.query();
// if(gr.next()){
//  alert("test");
//  g_form.showFieldMsg('user', "gr.user_name", "info");
// }



}
 
 
SI :-
 
var TestUserID = Class.create();
TestUserID.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   getUserID : function() {
    var users = [];
        var id = this.getParameter('sysparm_userID');
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id',id);
        gs.info("TestUserID" +gr.getEncodedQuery());
        gr.query();
        if(gr.next()){
            users.push(gr.getValue('user_name'));
        }
        gs.info("TestUserID"+users);
        return users.toString();
       
    },
    type: 'TestUserID'


});

@Revathi12 remove single inverted comma from ans

 

 

g_form.showFieldMsg('user', ans , 'info');

 

 

Try with the above

 

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

Regards,

Swathi Sarang