Show all active training list in Variable

aishwaryade3564
Tera Contributor

Hello

I have created 'Training Request Catalog' catalog were I want to create one variable 'List of trainings' it will Show all active training requests raised by ‘Requested for’ user in the table format. That table should contain Number, Training, Requested for & State fields from table "Training Request"

1)I have created UI macro and script include but not working

2) which variable type should select ? how to achive this

aishwaryade3564_0-1722333501324.pngaishwaryade3564_1-1722333538777.png

 

12 REPLIES 12

Bhavya11
Kilo Patron

Hi @aishwaryade3564 ,

 

i have try below  way to achieve this

Please modify the fields accordingly to your table

Create script include client callable

 

var TrainingRequestAjax = Class.create();
TrainingRequestAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getActiveTrainingRequests: function() {
        var requestedFor = this.getParameter('sysparm_requested_for');
        var gr = new GlideRecord('u_training_request');
        gr.addQuery('u_requested_for', gs.getUserID());
        gr.addActiveQuery();
        gr.query();

	var tableHTML = '<table class="table table-striped table-bordered">';
    tableHTML += '<thead><tr><th>Number</th><th>Training</th><th>Requested for</th><th>State</th></tr></thead>';
    tableHTML += '<tbody>';
    while (gr.next()) {
      tableHTML += '<tr>';
      tableHTML += '<td><a href="' + gr.getLink() + '">' + gr.getValue('number') + '</a></td>';
      tableHTML += '<td>' + gr.getDisplayValue('short_description') + '</td>';
      tableHTML += '<td>' + gr.getDisplayValue('u_requested_for') + '</td>';
      tableHTML += '<td>' + gr.getDisplayValue('state') + '</td>';
      tableHTML += '</tr>';
    }
    tableHTML += '</tbody></table>';
    return tableHTML;
  }
});

 

 

Ui Macro :

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<j:set var="requestedFor" value="${gs.getUserID()}" />
<div id="training_request_table"></div>
<script type="text/javascript">
  function loadTrainingRequests() {
    var ga = new GlideAjax('TrainingRequestAjax');
    ga.addParam('sysparm_name', 'getActiveTrainingRequests');
    ga.addParam('sysparm_requested_for', '${requestedFor}');
    ga.getXMLAnswer(function(response) {
      var result = response;
      document.getElementById('training_request_table').innerHTML = result;
    });
  }
  loadTrainingRequests();
</script>
</j:jelly>

 

 

 Output:

Bhavya11_0-1722338846415.png

 

Please mark helpful & correct answer if it's really worthy for you.

 

 

Thanks,

BK

 

aishwaryade3564
Tera Contributor

Hi @Bhavya11

As you written UI macro so in which variable type field should attach that UI macro. Macro type is not available.

 

Bhavya11
Kilo Patron

Hi @aishwaryade3564 ,

 

Please create variable type 'Custom' and type specification add your macro

 

Bhavya11_0-1722404739756.png

 

 

Bhavya11_1-1722404747940.png

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

aishwaryade3564
Tera Contributor

Hi @Bhavya11 

'List of Trainings' variable not visible and table also.