ServiceNow Widget Debugging: Temporarily Set Any Field Value (Without Touching Code)
Letโs be honestโฆ
Service Portal debugging is slow.
Every small change =
๐ Update script
๐ Save
๐ Reload
๐ Navigate back
๐ Test again
Repeat that 10 times and youโve already lost 20 minutes.
So hereโs a simple trick I use all the time to instantly set any field value inside a widget without changing code.
๐ก The Idea
Instead of modifying your widget or backend, you can:
๐ Directly update the Angular scope
๐ Inject any value you want
๐ Instantly see UI changes
No reload. No deployment.
โก Generic Approach (Works Everywhere)
Open DevTools โ Inspect the element โ Select the field you want to set value โ Run this:
var scope = angular.element($0).scope();
scope.$apply(function () {
scope.<object>.<field> = 'YOUR_TEMP_VALUE';
});๐ Example (Just to Visualise)
var scope = angular.element($0).scope();
scope.$apply(function () {
scope.data.user_id = '12345';
});๐ง How to Use This for Your Case
Replace:
<object>โ Where your data lives (data,c,child, etc.)<field>โ The field you want to modify
Common patterns:
// Client controller style
scope.c.data.status = 'approved';
// Server data
scope.data.short_description = 'Test value';
// Nested object
scope.item.details.name = 'Sample';๐ How to Find the Right Field
This is where most people struggle.
๐ After selecting element in DevTools:
var scope = angular.element($0).scope();
console.log(scope);
Now explore:
scope.datascope.cscope.itemscope.options
Youโll quickly find your target field.
โ ๏ธ Important (Donโt Skip This)
- Always use
$apply()โ otherwise UI wonโt refresh - This is temporary only (refresh = reset)
- No database update happens
- Use only for debugging/testing
๐ Why This is a Game Changer
You can:
โ Test UI conditions instantly
โ Simulate different states
โ Debug visibility issues
โ Avoid constant reloads
โ Move faster during development
๐งช Pro Tip (Handles Undefined Objects)
Sometimes the object doesnโt exist yet.
Use this safer version:
var scope = angular.element($0).scope();
scope.$apply(function () {
scope.data = scope.data || {};
scope.data.test_field = 'VALUE';
});๐ฅ Real-World Use Cases
I personally use this for:
- Testing approval states
- Simulating API responses
- Debugging conditional rendering
- Validating edge cases quickly
โ๏ธ Final Thought
This is not something youโll find in official docs.
But once you start using it,
๐ youโll never debug widgets the same way again.