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.data
  • scope.c
  • scope.item
  • scope.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.

Subscribe to karteek

Donโ€™t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe