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

Sandeep Rajput
Tera Patron
Tera Patron

@Meera_P 

You can't redirect user using business rules. Business rule scripts runs on the server side and can't be used for the refirection.

 

action.setRedirectURL

 

Redirection can only be done from a UI Action. For more information please refer to https://developer.servicenow.com/dev.do#!/reference/api/xanadu/server/no-namespace/ActionAPIBoth#Act...

 

Hope this helps.

 

Thank you for the information @Sandeep Rajput ,

Any suggestions how we can handle this situation?

@Meera_P The operation you are trying to perform should ideally be part of a UI Action, instead of a business rule.

@Sandeep Rajput ,

If we can not perform this function in BS.  How about can we add a link to the message like in change request after newly created record?  Just wanted to know if that is possible option.   Thank you

 

Meera_P_0-1727978497072.png