g_form.setValue not working on ServicePortal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 06:04 AM
Hi All,
I am using below script to populate a variable on submit of the catalog item. The script is working fine on desktop from Service Catalog but it is not working on Portal. The setValue is not working on portal alerts are generated on portal as well.
function onSubmit() {
//Type appropriate comment here, and begin script below
var mylist = g_form.getValue('user_s_to_be_created');
var answer = '';
var myarray = mylist.split(',');
for (var i =0; i< myarray.length; i++)
{
var getuser = new GlideRecord('sys_user');
getuser.addQuery('sys_id',myarray[i]);
getuser.query();
if(getuser.next()){
alert(getuser.user_name);
answer=getuser.user_name +","+ answer;
}
alert(answer);
}
g_form.setValue("user_s_amei", answer);
}
- Labels:
-
Request Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 06:05 AM
Make sure client script UI Type is set to All. Doing GlideRecord will not work in portal.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 06:37 AM
HI,
Glide Record is not supported on Service Portal. Change it to glideajax and use it in synchronous manner.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 06:40 AM
Hi,
GlideRecord won't work in service portal and hence it is breaking the code
I would recommend to set value to list collector on change of variable "user_s_to_be_created"
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2020 06:48 AM
Hi,
You should use glideAjax instead glideRecord cause in client script it's not recommended. Also, check if it is possible to change your field as a collector. However, I let you some code about how to use GA in your question:
// ClientScript onSubmit
function onSubmit() {
var mylist = g_form.getValue('user_s_to_be_created');
var ga = new GlideAjax('scriptIncludeName');
ga.addParam('sysparm_name','functionName');
ga.addParam('sysparm_list',mylist);
ga.getXMLAnswer(function(response) {
g_form.setValue("user_s_amei", response);
});
}
//Script Include codes
var arrUser = [];
var list = this.getParameter('sysparm_list');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id','IN', list.join());
gr.query();
while(gr.next()) {
arrUser.push(gr.user_name);
}
return arrUSer.join();
If it was helpful, please give positive feedback.
Thanks,
☆ Community Rising Star 22, 23 & 24 ☆