Business Rule - Code Review and Assistance with Task Redirection Issue

Meera_P
Tera Expert

Hello,

The blow business rule script currently trigger on RITM table and  successfully creates a new task. However, I'm struggling to redirect it to the newly created record. Could someone please review the code and offer suggestions on how to make this work?

 

Your assistance would be greatly appreciated.

 

(function executeRule(current, previous /*null when async*/ ) {

    if (current.description == 'software') {

        var gr = new GlideRecord('sc_task');
        gr.initialize();
        gr.request_item = current.sys_id;
        gr.short_description = 'New task for software request';
        gr.description = 'test';
        
        // Insert the new record and get the sys_id
        var newRecordSysId = gr.insert();
        
        if (newRecordSysId) {
            gs.addInfoMessage('New task ' +gr.number);
           
		    // Redirect to the newly created record
            action.setRedirectURL('/sc_task.do?sys_id=' + newRecordSysId);
        
		} else {
            gs.addErrorMessage('Failed to create the record.');
        }
    }

})(current, previous);

 

1 ACCEPTED SOLUTION

@Meera_P Yes, you can create an info message and add the link of your record to it. Here is how you can do it https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0691931

 

Please mark my response helpful and accepted solution if it addresses your question. You can mark more than one answer as accepted solution.
 

View solution in original post

7 REPLIES 7

@Meera_P Yes, you can create an info message and add the link of your record to it. Here is how you can do it https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0691931

 

Please mark my response helpful and accepted solution if it addresses your question. You can mark more than one answer as accepted solution.
 

@Sandeep Rajput 

 

Your suggestion has been extremely effective. Thanks to your help, we’ve successfully resolved this issue. We truly appreciate your support!

Your reference is to 'Server Scoped' API documentation, seems to work from server-side code.