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

Community Alums
Not applicable

Hi @Revathi12 ,

I tried your problem in my PDI and it works for me, Please refer below image 

I created onChange client script and add below code 

SarthakKashya2_0-1713357873218.png

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

   //Type appropriate comment here, and begin script below
   alert("New Value = " + newValue);
   var gr = new GlideRecord('sys_user');
   gr.addQuery('sys_id', newValue);
   gr.query();
   if(gr.next()){
	g_form.showFieldMsg('select_user', gr.user_name, "info");
   }
}

You can add showFieldMsg method to show the id 

Here's the result 

 

 

SarthakKashya2_1-1713357929593.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

 

 

 

Hello @Community Alums 

 

Thanks for the response. I have tried using Ajax calls, Could you please let me know if I'm missing something here

 

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('user_id',id);
        gs.info("TestUserID" +gr.getEncodedQuery());
        gr.query();
        while(gr.next()){
            users.push(gr.name.getValue());
        }
        gs.info("TestUserID"+users);
        return users.toString();
       
    },
    type: 'TestUserID'


});
 
 
Client Script :-
 
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 answer = response.responseXML.documentElement.getAttribute("answer");
    alert(answer);

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





}

Community Alums
Not applicable

Hi @Revathi12 ,

I checked your code there is two small issues I got and I fixed them please try below code 

Script Include

getUserID: function() {
        var users = [];
        var id = this.getParameter('sysparm_user_name');
		gs.log('IDIID = ' + id);
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', id);
        gr.query();
        while (gr.next()) {
            users.push(gr.getValue('name'));
        }
        gs.info("TestUserID" + users);
        return users.toString();

    },

 

Client Script

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

    //Type appropriate comment here, and begin script below
    alert('Here showUserId = ' + newValue);
    var ga = new GlideAjax('catalogCS');
    ga.addParam('sysparm_name', 'getUserID');
    ga.addParam('sysparm_user_name', newValue);
    ga.getXML(HelloWorldParse);

    function HelloWorldParse(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert(answer);
    }
}

 

I hope this will work fine now 

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

Hi @Community Alums 

 

I wanted to display user as field message. There is a variable, when we select user as input below it should display field message of user id selected in user field.