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

Hi @M_iA ,

I think you are missing one line.

 

 var checkboxResponse = g_form.getValue('update_my_profile');
g_form.addInfoMessage(checkboxResponse);
    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');
ga.getXMLAnswer();
    }

 

Try This script and see if its working or not. Also check if the addinfoMessage that was added is getting triggered as well.

 

Regards,

Johns

Thats deffinately a step forward @Johns Marokky 

It is now updating the number, but I am getting

M_iA_0-1678466968264.png

and in the console, im getting:

Unhandled exception in GlideAjax.

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

Thanks @Johns Marokky 

Its working as expected

Johns Marokky
Tera Guru

Hi @M_iA ,

Can you make sure that the onSubmit and Script include are created on the same scope.

And its accessible by all scopes.

 

Mark helpful if it helps in solving your query.

 

Regards,

Johns