
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 03:14 AM
Hi, I have a variable set which is used on about 100 record producers. I have added a field to the variable set which is populated with the contact phone number of the user. I also have a checkbox next to it. If selected, the phone number field is no longer read only and the user can update.
Onsubmit, if this field is checked, I want this to update the record on the sys_user table with the new phone number.
As the variable set is on 100 RP's, I dont want to go into every single RP to add to the script.
Is there a way I can do this with an OnSubmit catalog client script similar to how the map to field functionality works?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 09:00 AM
Hi @M_iA ,
Try the below script.
var checkboxResponse = g_form.getValue('update_my_profile');
if (checkboxResponse == 'true' || checkboxResponse == true) {
var ga = new GlideAjax('global.CustomerHelpCenterUtils');
ga.addParam('sysparm_name', 'setContactNumber');
ga.addParam('sysparm_number', g_form.getValue('contact_number'));
ga.addParam('sysparm_user', g_form.getValue('contact'));
ga.getXMLAnswer(myCallbackFunction);
function myCallbackFunction() {
return;
}
Mark helpful and accept the solution if it helps in Solving your query
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 03:45 AM
Hi @M_iA you can write onsubmit client script
if(g_form.getValue('checkbox')==true)
{
var ga = new GlideAjax('script include name');
ga.addParam('sysparm_name', 'function name');
ga.addParam('sysparm_number', g_form.getValue("contact number"));
ga.addParam('sysparm_user', g_form.getValue("User"));
ga.getXML(updateCampus);
}
Script include
var script include name = Class.create();
script include name.prototype = Object.extendsObject(AbstractAjaxProcessor, {
function name: function () {
var contact= this.getParameter('sysparm_number');
var userid=this.getParameter('user');
var user= new GlideRecord('sys_user');
if (user.get(userid))
{
user.mobile_phone =contact;
user.update();
}
}
}
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 04:21 AM
Thanks for the help @priyasunku
I have tried with the following:
Catalog Client Script
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('update_my_profile') == true)
{
var ga = new GlideAjax('CustomerHelpCenterUtils');
ga.addParam('sysparm_name', 'setContactNumber');
ga.addParam('sysparm_number', g_form.getValue("contact_number"));
ga.addParam('sysparm_user', g_form.getValue("contact"));
ga.getXML(setContactNumber);
}
}
Script Include
var CustomerHelpCenterUtils = Class.create();
CustomerHelpCenterUtils.Object.extendsObject(AbstractAjaxProcessor, {
setContactNumber: function() {
var contact = this.getParameter('sysparm_number');
var userid = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
if (user.get(userid))
{
user.phone = contact;
user.update();
}
}
});
But its not working and phone field is not being updated. Any ideas? Can you spot something that I may have done wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 04:25 AM
@M_iA may i know what error you are getting. can you please keep logs and check in each stage if it entering the script.
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 04:40 AM
adding logs to the script include suggest that its not even hitting the script include. Nothing is returning in the logs after:
setContactNumber: function() {
var contact = this.getParameter('sysparm_number');
gs.log('MTA number: ' + contact);