Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Not able to update the record after saving modal in the workspace

bhattahemas
Tera Contributor

I'm getting this error when I open modal and choose a record and save it in the workspace, the actual requirement is to update the current record from where I opened the ui action

function onClick(g_form) {

    var ga = new GlideAjax('service');
    ga.addParam('sysparm_name', 'getAccount');
    ga.addParam('sysparm_service', g_form.getUniqueValue());

    ga.getXMLAnswer(function(answer) {
        alert(answer);
        var taskRecord = g_form.getUniqueValue();
        var rawQuery = 'u_account.nameLIKE' + answer +
            '^u_configuration_item.ref_service_offering.u_service_class=3rd Party';
        var url = 'accounts_list.do?' +
            'sysparm_query=' + encodeURIComponent(rawQuery) +

            '&sysparm_stack=no' +
            '&sysparm_workspace=true' +
            '&sysparm_view=popup2' +
            '&sysparm_referring_id=' + taskRecord +
            '&sysparm_referring_table=incident';
        alert('final url' + url);

        g_modal.showFrame({
            title: 'List of Services',
            url: url,
            size: 'lg',
            height: '22rem',
			callback: function() {
                g_form.reload();
            }
        });

    });

}

image.png

3 REPLIES 3

Naveen20
ServiceNow Employee

You're already passing sysparm_referring_id and sysparm_referring_table in the URL — use those inside the modal's save script instead of relying on g_form:

 
// Inside your saveAcc / modal script — extract from URL params, not g_form
var urlParams = new URLSearchParams(window.location.search);
var referringId    = urlParams.get('sysparm_referring_id');
var referringTable = urlParams.get('sysparm_referring_table');

Then use a GlideAjax call to update the parent incident server-side:

 
var ga = new GlideAjax('service');
ga.addParam('sysparm_name', 'updateIncident');
ga.addParam('sysparm_incident_id', referringId);
ga.addParam('sysparm_selected_value', selectedValue);
ga.getXMLAnswer(function(response) {
    // close the modal after update
    window.parent.postMessage({ action: 'close_modal' }, '*');
});

subhamsni92
Tera Contributor

Error is coming because You passed g_form as a parameter in the function, which overrides the default ServiceNow g_form object. Due to this, getUniqueValue() is not available.

Fix: remove g_form from function parameters and use the default g_form.

subhamsni92
Tera Contributor

The issue is caused because g_form is being passed as a parameter in the function, which overrides the default ServiceNow g_form object. As a result, methods like getUniqueValue() are not available.

In ServiceNow client-side scripts (like UI Actions), g_form is already available by default, so it should not be passed as a parameter.

Fix: Remove g_form from the function parameters and use the default g_form object.