We are currently experiencing intermittent login issues on Community.  The team is actively working on a fix.

[Variable Editor] data and g_form not updating after save — deleted variables reappear

naoooooooo
Tera Contributor

Summary

I’m developing a custom Variable Editor widget in Service Portal.
When I delete an item (a variable row) and click “Save,” the deletion is correctly reflected in the database.
However, after saving, the deleted row reappears in the Variable Editor, as if the data or g_form objects were not refreshed.


Environment

  • ServiceNow: Washington.D.C

  • Widget: Custom (based on the Variable Editor OOTB widget)

  • Client Script: AngularJS controller calling c.server.get()


Issue Details

  1. A variable row is deleted from a custom table

  2. After saving, the database is correct (the deleted record is inactive)

  3. The widget refreshes, but the deleted row appears again

  4. Tried both spUtil.refresh($scope) and g_form.submit(), but both reload the old data


Expected Behavior

After saving (c.server.get() finishes):

  • The latest variable JSON should be reflected in both data and g_form

  • Deleted rows should not reappear on the UI

 

Question

What is the best practice to ensure that:

  1. The widget’s $scope.data and g_form reflect the latest data after saving

Any advice on how to correctly refresh or update g_form after saving would be greatly appreciated.

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@naoooooooo 

what's your actual business requirement and share some screenshots.

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

Sarthak Kashyap
Mega Sage

Hi @naoooooooo ,

 

Can you please try to use below script 

Client script

c.deleteRow = function(rowSysId) {
        c.server.get({
            action: 'deleteRow',
            sys_id: rowSysId
        }).then(function(response) {
            alert("Variable deleted successfully");
        };
    };

rowSysId you have to send from HTML when call the function deleteRow.

 

Server Side

if (input && input.action === 'deleteRow') {
        var gr = new GlideRecord('your_table_name');
        if (gr.get(input.sys_id)) {
            gr.active = false; 
            gr.update();
        }
    }

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak