g_form.setValue not working on ServicePortal

RohanBathla
Tera Contributor

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);
}

5 REPLIES 5

Mike Patel
Tera Sage

Make sure client script UI Type is set to All. Doing GlideRecord will not work in portal.

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

Glide Record is not supported on Service Portal. Change it to glideajax and use it in synchronous manner.


Thanks,
Ashutosh

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Adrian Ubeda
Mega Sage
Mega Sage

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, 

 

If it was helpful, please give positive feedback! ✔
☆ Community Rising Star 22, 23 & 24 ☆