#ServiceNow1 min read

ServiceNow Widget Debugging: Temporarily Set Any Field Value (Without Touching Code)

Karteek Nidubrolu·

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.

K

Written by

Karteek Nidubrolu