Business rule not working
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi Everyone,
I am trying to create Incident for the failed ATF tests and I am using business rule to create them. I am using the below business rule and the incident is getting created but with undefined values in the description field.
Please let me know where I am doing wrong or is any other way.
When to Run:
when : after
Insert: checked
Update: checked
Filter condition: Status is Failure
Script:
Output:
Description:
An ATF test has failed.
Test Name: undefined
Failure Message: undefined
Executed By: undefined
Execution Time: undefined
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Seems your field names etc are wrong, check below
BR should be on "sys_atf_test_result"
Condition: Status [Changes To] Error
Script:
(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here(function executeRule(current, previous) {
    var testName = current.test.name || current.test; // Get test name
    gs.info('ATF failure detected for test: ' + testName);
    var failureMessage = current.first_failing_step ? current.first_failing_step.summary : 'N/A';
    // Get user display name from sys_created_by reference
    var executedBy = 'Unknown';
    if (current.sys_created_by) {
        var userGR = new GlideRecord('sys_user');
        if (userGR.get('user_name', current.sys_created_by)) {
            executedBy = userGR.getDisplayValue();
        }
    }
    var executionTime = current.getValue('start_time');
    var inc = new GlideRecord('incident');
    inc.initialize();
    inc.short_description = 'ATF Test Failed: ' + testName;
    inc.description =
        'An ATF test has failed.\n\n' +
        'Test Name: ' + testName + '\n' +
        'Failure Message: ' + failureMessage + '\n' +
        'Executed By: ' + executedBy + '\n' +
        'Execution Time: ' + executionTime + '\n\n';
    inc.contact_type = 'self-service';
    inc.category = 'incident';
    inc.u_choice_issue = 'other'; // Adjust if needed
    inc.impact = 3;
    inc.urgency = 2;
    var incSysId = inc.insert();
    if (incSysId) {
        gs.info('Incident created for failed ATF test: ' + testName + ' (Sys ID: ' + incSysId + ')');
    } else {
        gs.warn('Failed to insert incident for ATF test: ' + testName);
    }
})(current, previous);💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
