Show all active training list in Variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 03:00 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 04:28 AM
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:
Please mark helpful & correct answer if it's really worthy for you.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 10:43 PM
Hi @Bhavya11
As you written UI macro so in which variable type field should attach that UI macro. Macro type is not available.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 10:46 PM
Hi @aishwaryade3564 ,
Please create variable type 'Custom' and type specification add your macro
Please mark helpful & correct answer if it's really worthy for you.
Thanks,
BK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 11:44 PM
Hi @Bhavya11
'List of Trainings' variable not visible and table also.