Need help to make the code work dynamically

Piyushh_garg1
Tera Contributor

Hello Experts,

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 table .

its showing the correct Ticket number but in the current behaviour it is only searching in the change_request table 

 

<div ng-if="data.isValid">
<div class="panel panel-{{::options.color}} b">
  <div class="panel-heading">
    <h2 class="panel-title">${Approval request for {{::task.table}} {{::task.number.display_value}}}</h2>
  </div>

  <div class="panel-body">
    
    <div ng-if="task.u_change_owner"><label>${Change Owner}</label> {{::task.u_change_owner.display_value}}</div>
   <div ng-if="task.risk"><label>${Risk}</label> {{::task.risk.display_value}}</div>
     <div ng-if="task.category"><label>${Category}</label> {{::task.category.display_value}}</div>
 <div ng-if="task.cmdb_ci"><label>${Configuration item}</label> {{::task.cmdb_ci.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>
 <div ng-if="task.change_plan"><label>${Implementation plan}</label> {{::task.change_plan.display_value}}</div>
    <div ng-if="task.u_testing_evidence"><label>${Pre Implementation plan}</label> {{::task.u_testing_evidence.display_value}}</div>
   
  <p>
    </p>
    <div ng-if="task.number"> <p>Please click here to open the Change record <a href="/change_request.do?sys_id={{::task.sys_id.display_value}}" target="_blank">{{::task.number.display_value}}</a></p></div>
    <div ng-if="task.quantity">${Quantity} {{::task.quantity.display_value}}</div>
    <div ng-if="task.price.value > 0"><label>${Price}</label> {{::task.price.display_value}}

 

 

6 REPLIES 6

Maddysunil
Kilo Sage

@Piyushh_garg1 

I think ,To make the code pick the table dynamically depending on whether it is a request item table, change request table, or any other task table, you can modify the link generation part where you specify the URL. Instead of hardcoding the table name, you can dynamically determine it based on the task table attribute.

Below is the sample code:

 

 

<div ng-if="data.isValid">
  <div class="panel panel-{{::options.color}} b">
    <div class="panel-heading">
      <h2 class="panel-title">${Approval request for {{::task.table}} {{::task.number.display_value}}</h2>
    </div>

    <div class="panel-body">
      <!-- Other task details -->
      <div ng-if="task.number"> 
        <p>Please click here to open the Change record 
          <a ng-href="/{{::task.table}}.do?sys_id={{::task.sys_id.display_value}}" target="_blank">{{::task.number.display_value}}</a>
        </p>
      </div>
      <!-- Other task details -->
    </div>
  </div>
</div>

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

 

Anirudh Pathak
Mega Sage

Hi @Piyushh_garg1 ,

It might be the case that while giving link to the "Task" record you are pointing to "change_request" table.

Please try the below code -

<div ng-if="data.isValid">
<div class="panel panel-{{::options.color}} b">
  <div class="panel-heading">
    <h2 class="panel-title">${Approval request for {{::task.table}} {{::task.number.display_value}}}</h2>
  </div>

  <div class="panel-body">
    
    <div ng-if="task.u_change_owner"><label>${Change Owner}</label> {{::task.u_change_owner.display_value}}</div>
   <div ng-if="task.risk"><label>${Risk}</label> {{::task.risk.display_value}}</div>
     <div ng-if="task.category"><label>${Category}</label> {{::task.category.display_value}}</div>
 <div ng-if="task.cmdb_ci"><label>${Configuration item}</label> {{::task.cmdb_ci.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>
 <div ng-if="task.change_plan"><label>${Implementation plan}</label> {{::task.change_plan.display_value}}</div>
    <div ng-if="task.u_testing_evidence"><label>${Pre Implementation plan}</label> {{::task.u_testing_evidence.display_value}}</div>
   
  <p>
    </p>
    <div ng-if="task.number"> <p>Please click here to open the Change record <a href="/{{::task.table}}?sys_id={{::task.sys_id.display_value}}" target="_blank">{{::task.number.display_value}}</a></p></div>// Updated this line to pick the table name dynamically
    <div ng-if="task.quantity">${Quantity} {{::task.quantity.display_value}}</div>
    <div ng-if="task.price.value > 0"><label>${Price}</label> {{::task.price.display_value}}

 

Piyushh_garg1
Tera Contributor

@Maddysunil @Anirudh Pathak 
It didnt helped 
its picking up the full name as requested item 

Piyushh_garg1_0-1710928667102.png

 

@Piyushh_garg1 

Try this one:

 

<div ng-if="data.isValid">
  <div class="panel panel-{{::options.color}} b">
    <div class="panel-heading">
      <h2 class="panel-title">${Approval request for {{::getTableName(task.table)}} {{::task.number.display_value}}</h2>
    </div>

    <div class="panel-body">
      <!-- Other task details -->
      <div ng-if="task.number"> 
        <p>Please click here to open the Change record 
          <a ng-href="/{{::getTableName(task.table)}}.do?sys_id={{::task.sys_id.display_value}}" target="_blank">{{::task.number.display_value}}</a>
        </p>
      </div>
      <!-- Other task details -->
    </div>
  </div>
</div>

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks