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 ,

Please update your client script code as below

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('user_name'));
        }
        gs.info("TestUserID" + users);
        return users.toString();

    },

Client Script 

 

 

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);
		g_form.showFieldMsg('select_user', answer, "info");
    }

 

 

Here's the result

SarthakKashya2_0-1713891635318.png

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

 

Thanks and Regards 

Sarthak

 

swathisarang98
Giga Sage
Giga Sage

Hi @Revathi12 ,

 

I have updated your code below ,

It will show you the user id of the user selected

 

Client script:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
   // alert(newValue);
    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');
    }



}

 

 

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);
        gr.query();
        if(gr.next()) {
		//	gs.info('inside if');
            users.push(gr.getValue('user_name'));
        }
      //  gs.info("TestUserID" + users);
		return users.toString();

    },
    
    type: 'TestUserID'
});

 

 

In si just replace gr.getValue('user_name');

 

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

Regards,

Swathi Sarang

Hi @SwathiSarang ,

Thanks for response.

 

I checked the code, its printing the answer instead of user ID.

Hi @Revathi12 ,

 

yes because ans will have the user id actually which will be coming from script include.

 

Did you copy the code exactly and do make changes for field name if it is different

 

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

Regards,

Swathi Sarang

@Revathi12 i have tried it in my pdi it works,

swathisarang98_0-1713887960926.png

 

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

Regards,

Swathi Sarang