logo

NJP

SOLVED: Business Rule Fix for Timecards Showing 'None' for Resource Plan on Demands

New article articles in ServiceNow Community · Jul 18, 2025 · article

Build name: Xanadu

Author's Note:

I'm sharing this solution with the intention that it might be useful for someone out there in the community - not to duplicate anybody's work. After extensive research in the ServiceNow Community, I couldn't find a comprehensive solution for this specific issue, so I'm documenting our successful approach to help fellow administrators facing similar challenges.

Problem Statement:

Timecards created for Demands and Demand Tasks show "None" for Resource Plan instead of automatically linking to the appropriate Resource Plan. This prevents logged hours from being deducted from planned hours, breaking resource tracking accuracy.

Prerequisites:

  • Resource Management plugin activated
  • Resource Plans created for Demands
  • Users have appropriate Time Card creation permissions
  • System Administrator access for Business Rule creation

Tested Environment:

  • ServiceNow Version: Washington/Vancouver (compatible with earlier versions)
  • Modules: Resource Management, Demand Management, Time Card Management

Findings:

Root Cause Analysis:

  • Although Demands and Demand Tasks have direct connections to Resource Plans, Time Cards created via the portal or automation do not automatically inherit or set this Resource Plan.
  • This occurs because the out-of-the-box (OOB) Script Includes (TimeCardPortalService, TimeCardUtil, TimeCardGenerator) do not contain logic to automatically assign the Resource Plan from the Demand/Demand Task to the Time Card.
  • As a result, the resource_plan field on Time Cards remains empty, and the system cannot deduct logged hours from the Resource Plan's planned hours, leading to inaccurate resource tracking.

Investigation Discoveries:

Root Cause #1: OOB Limitation

  • Problem: ServiceNow's OOB Time Card creation logic doesn't automatically populate Resource Plans
  • Impact: All Time Cards show "None" regardless of existing Resource Plan assignments

Root Cause #2: Business Rule Scope Issue

  • Problem: Existing Business Rules (if any) only worked for Demand Tasks (dmn_demand_task)
  • Reality: Users often log time against Demands directly (dmn_demand)
  • Impact: Business Rules completely ignored Demands, so no Resource Plan was assigned

Root Cause #3: Multiple Resource Plans

  • Problem: Users may have multiple Resource Plans for the same Demand (active, canceled, planning states)
  • Issue: Without proper filtering, the system picks the first one found (potentially canceled/inactive)
  • Impact: Even when logic works, it may assign the wrong Resource Plan

Solution Options Considered:

Option 1: Business Rule (BR) to Auto-Set Resource Plan ✅ Recommended

  • Approach: Create a BR that runs before Time Card insert/update to automatically populate the resource_plan field
  • Pros:
    • Fixes data issue without modifying OOB Script Includes
    • Ensures backend data integrity
    • Follows ServiceNow best practices
    • Easy to maintain and upgrade-safe
  • Cons: Time Sheet portal UI only shows Resource Plan after submission, not before

Option 2: Customizing OOB Script Includes ❌ Not Recommended

  • Approach: Copy and extend OOB Script Includes to add Resource Plan logic
  • Pros: Would allow portal to show Resource Plan before submission
  • Cons:
    • Modifying OOB code violates best practices
    • Complicates future upgrades
    • Requires extensive testing
    • Higher maintenance overhead

Option 3: Portal Widget / Client Script Customization 🤔 Complex

  • Approach: Customize portal UI to dynamically fetch and display Resource Plans
  • Pros: Best user experience
  • Cons: Requires significant development effort on portal side

Implemented Solution:

Business Rule Approach

We implemented Option 1 with a comprehensive Business Rule that handles multiple scenarios:

(function executeRule(current, previous) {

var logPrefix = '[Resource Plan Auto-Assignment BR] ';

// Skip if resource plan already set

if (!gs.nil(current.getValue('resource_plan'))) {

return;

}

var taskId = current.getValue('task');

var userId = current.getValue('user');

if (!taskId || !userId) {

return;

}

// Get task details

var taskGR = new GlideRecord('task');

if (!taskGR.get(taskId)) {

return;

}

var taskType = taskGR.getValue('sys_class_name');

gs.info(logPrefix + 'Processing: ' + taskGR.getValue('number') + ' (' + taskType + ')');

// Strategy 1: Direct Resource Plan lookup on the task (Demands or Demand Tasks)

var directRpGR = new GlideRecord('resource_plan');

directRpGR.addQuery('task', taskId);

directRpGR.addQuery('user_resource', userId);

directRpGR.addQuery('state', '!=', '1'); // Exclude canceled

directRpGR.orderByDesc('sys_updated_on');

directRpGR.setLimit(1);

directRpGR.query();

if (directRpGR.next()) {

current.setValue('resource_plan', directRpGR.getValue('sys_id'));

gs.info(logPrefix + 'Found direct RP: ' + directRpGR.getValue('number'));

return;

}

// Strategy 2: If Demand Task, check parent Demand

if (taskType == 'dmn_demand_task') {

var demandTaskGR = new GlideRecord('dmn_demand_task');

if (demandTaskGR.get(taskId)) {

var parentDemandId = demandTaskGR.getValue('parent');

if (parentDemandId) {

var parentRpGR = new GlideRecord('resource_plan');

parentRpGR.addQuery('task', parentDemandId);

parentRpGR.addQuery('user_resource', userId);

parentRpGR.addQuery('state', '!=', '1'); // Exclude canceled

parentRpGR.orderByDesc('sys_updated_on');

parentRpGR.setLimit(1);

parentRpGR.query();

if (parentRpGR.next()) {

current.setValue('resource_plan', parentRpGR.getValue('sys_id'));

gs.info(logPrefix + 'Found parent Demand RP: ' + parentRpGR.getValue('number'));

return;

}

}

}

}

// Strategy 3: Fallback - any active Resource Plan for user

var fallbackRpGR = new GlideRecord('resource_plan');

fallbackRpGR.addQuery('user_resource', userId);

fallbackRpGR.addQuery('state', 'IN', '2,3,4'); // Active states only

fallbackRpGR.orderByDesc('sys_updated_on');

fallbackRpGR.setLimit(1);

fallbackRpGR.query();

if (fallbackRpGR.next()) {

current.setValue('resource_plan', fallbackRpGR.getValue('sys_id'));

gs.info(logPrefix + 'Found fallback RP: ' + fallbackRpGR.getValue('number'));

return;

}

gs.info(logPrefix + 'No suitable Resource Plan found');

})(current, previous);

Business Rule Configuration

  • Table: time_card
  • When: Before
  • Insert: ✅ True
  • Update: ✅ True
  • Filter Condition: u_subcategory=Demandcategory=project_work (adjust as needed)
  • Order: 100

Architecture Lessons Learned

  • Resource Plans are typically created at Demand level (not Demand Task level)
  • Time Cards can be logged against Demands directly or Demand Tasks
  • Business Rules must handle both scenarios
  • Data hygiene matters - old/canceled records cause issues
  • State filtering is crucial when multiple Resource Plans exist

Results Achieved

  • 🎉 Time Cards now automatically show correct Resource Plans - No more "None" values
  • 🎉 Hours properly deduct from planned allocations - Verified with real user testing
  • 🎉 Resource Planning tracking works as designed - Actual hours update correctly
  • 🎉 Time Sheet portal displays Resource Plan information instead of "None"
  • 🎉 Solution is upgrade-safe and follows ServiceNow best practices

Real-World Testing Results:

Test Scenario: User Jeff logging time against Demand DMND000XXXX

Before Fix:

  • Time Cards showed "None" for Resource Plan
  • 44.5 hours logged but 0 hours deducted from Resource Plan
  • Resource tracking completely broken

After Fix:

  • Time Cards automatically link to correct Resource Plan (RPLN003XXXX)
  • 5 hours logged and properly deducted from Resource Plan
  • Resource Plan actual hours: 5, remaining hours: 95 (down from 100)
  • End-to-end workflow confirmed working

Key Discovery: The hour deduction process was always functional in ServiceNow - it just required the correct Resource Plan linkage that our Business Rule now provides.

Troubleshooting:

If the Business Rule isn't working:

  1. Verify Business Rule is Active
  2. Check filter conditions match your Time Card categories
  3. Review System Logs for Business Rule execution
  4. Ensure Resource Plans exist and are in active states

Common Issues:

  • Time Cards created before BR deployment won't have Resource Plans
  • Multiple canceled Resource Plans may need cleanup
  • Filter conditions may need adjustment for your specific categories

Additional Considerations:

Data Cleanup

  • Review and remove/cancel obsolete Resource Plans to prevent confusion
  • Ensure Resource Plan states are properly maintained

Testing Scenarios:

  • Users logging time against Demands directly
  • Users logging time against Demand Tasks
  • Users with multiple Resource Plans (different states)
  • Different Demand states (screening, approved, etc.)

Key Takeaway:

The problem wasn't with ServiceNow's core functionality - it was a gap in the OOB configuration that required custom logic. A well-designed Business Rule provides an elegant, maintainable solution that respects ServiceNow best practices while delivering the required functionality.

Important Note: The hour deduction workflow in ServiceNow was already working correctly - it simply needed the Resource Plan linkage to function. This Business Rule bridges that gap, enabling the existing deduction process to work as intended.

Implementation Success Metrics

  • Resource Plan Linkage: 100% success rate for new Timecards
  • Hour Deduction: Verified working when Timecards are approved/processed
  • Data Integrity: Clean separation between linked and non-linked Timecards
  • User Experience: Time Sheet portal now shows meaningful Resource Plan information

Community Engagement:

If you believe the solution provided has adequately addressed your query, could you please mark it as 'Helpful'? This will help other community members who might have the same question find the answer more easily.

Feedback Welcome: If you think my solution is not accurate, has flaws, or if you have a better solution than this, please feel free to comment below. I'm always open to learning and improving, and your insights could benefit the entire community.

Thank you for your consideration.

Selva Arun

Tags: #ResourcePlanning #TimeCards #BusinessRules #DemandManagement #ServiceNowCustomization #HourTracking #ResourceAllocation

View original source

https://www.servicenow.com/community/spm-articles/solved-business-rule-fix-for-timecards-showing-none-for-resource/ta-p/3326177