Map to field functionality

M_iA
Kilo Sage

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?

1 ACCEPTED SOLUTION

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

View solution in original post

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

@M_iA 

record producer is on which table?

did you debug your scripts?

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

Hi @Ankur Bawiskar 

 

record producer sits on the sn_customerservice_case table.

 

Yes, I have added the following to the script include, but nothing showing in the logs suggesting that its not even getting as far as the script include?

 

var CustomerHelpCenterUtils = Class.create();
CustomerHelpCenterUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    setContactNumber: function() {
        var contact = this.getParameter('sysparm_number');
		gs.log('MTA number: ' + contact);
        var userid = this.getParameter('sysparm_user');
        var user = new GlideRecord('sys_user');
        if (user.get(userid))
        {
            user.phone = contact;
            user.update();
        }
    }
});

@M_iA 

 

try using gs.info() for logs and check. Also check if it is entering client script

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful

@M_iA 

if you are in scoped app then use gs.info() as gs.log() won't work

are both the scripts in same scope?

Is your script include client callable?

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

@Ankur Bawiskar @priyasunku 

 

I have updated:

M_iA_0-1678465077395.png

But it still isnt adding to the logs. Both scripts are in global scope.

 

I also, update the client script:

function onSubmit() {
    //Type appropriate comment here, and begin script below
    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'));
        alert('I got here');
    }
}

And alert popup does trigger