We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

how to print display value of field in client script?

venkatrajesh
Tera Expert
Hi i am trying to print Assignment group filed value ,i have tried as below but not working

  var group1 = g_form.getValue('assignment_group');

  var group2 = g_form.getDisplayValue('assignment_group');

  var   group3 = g_form.getDisplayBox('assignment_group');

g_form.addInfoMessage("group1"+ group1);

g_form.addInfoMessage("group2"+ group2);

g_form.addInfoMessage("group3"+ group3);

g_form.addInfoMessage("group value"+sys_user_group.assignment_group);

5 REPLIES 5

dvp
Mega Sage

you need to use get reference function.



Try the below script



var group1 = g_form.getReference('assignment_group', callBack);



function callBack(group1){



if(group1){



g_form.addInfoMessage("group1"+ group1.name);


}



}


johansec
Tera Guru

This should work



// Get the group record


    var gr = new GlideRecord('sys_user_group');


    gr.addQuery('sys_id', g_form.getValue('assignment_group'));


    gr.query(getGroupName);




    // Get the name in a callback function


    function getGroupName(gr) {


  while (gr.next()) {


  var assignmentGroupName = gr.name;


  }


  }


venkatrajesh
Tera Expert

got the solution:below script able to get the value in   AassignmentGroup



var group = g_form.getReference('assignment_group');


g_form.addInfoMessage("group "+ group.name);


If the above script is on catalog items/record producers, please note that your script will not work in Service Portal side