[Variable Editor] data and g_form not updating after save — deleted variables reappear
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
A variable row is deleted from a custom table
After saving, the database is correct (the deleted record is inactive)
The widget refreshes, but the deleted row appears again
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
what's your actual business requirement and share some screenshots.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
