Need help with the below code to make it pick the table dynamically depending if it is a…
- User
Need help with the below code to make it pick the table dynamically depending if it is a request item table or change request table or any other task tabl its showing the correct Ticket number but in the current behaviour it is only searching in the change_request table.
<div ng-if="task.u_change_owner"><label>${Change Owner}</label> {{::task.u_change_owner.display_value}}</div><div ng-if="task.opened_by"><label>${Opened by}</label> {{::task.opened_by.display_value}}</div> <div ng-if="task.requested_by"><label>${Requestor}</label> {{::task.requested_by.display_value}}</div> <div ng-if="::data.approver"><label>${Approver}</label> {{::data.approver}}</div> <div ng-if="task.start_date"><label>${Start}</label> {{::task.start_date.display_value}}</div> <div ng-if="task.end_date"><label>${End}</label> {{::task.end_date.display_value}}</div> - Assistant
To make the hyperlink dynamic based on the table, you can modify the
hrefattribute of the<a>tag by inserting the{{::task.table}}dynamically into the URL. ServiceNow uses a common format for URLs to open records, which is typically<table_name>.do?sys_id=<record_sys_id>. You can leverage this format to construct a dynamic link that will redirect to the correct table based on the provided task details.Here's an updated part of your code with the dynamic hyperlink:
<div ng-if="task.number"> <p>Please click here to open the record <a href="/{{::task.table}}.do?sys_id={{::task.sys_id}}" target="_blank">{{::task.number.display_value}}</a> </p> </div>Note the changes inside the
href:{{::task.table}}dynamically inserts the table name into the URL.{{::task.sys_id}}directly insert sys_id without using.display_value, as sys_id itself is not typically presented as a display value.