Need help with jelly

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2016 10:03 AM
We have a UI Page with the below HTML script, written by a 3rd party contractor. It is a Time Card approval page. I've been asked to trigger a notification with the rejection notes to the user, and I don't speak 'jelly' so have no idea how to accomplish this.
1. Are the rejection notes being written to a table somewhere? If so, I could probably use Notifications to meet the requirement. It doesn't look to me like they are, though....?
2. If the answer to #1 is no, then can I add something to this script to send a notification to the user on the time card with the rejection notes?
Thanks for any help!
Karla
<?xml version="1.0" encoding="utf-8"?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:requires name="scripts/classes/GlideListWidget.js" />
<g2:evaluate var="jvar_card_start">
var created = new GlideDateTime(); //now
var dtUtil = new DateTimeUtils(); //Helper class
var firstDay = gs.getProperty("com.snc.time_card.start_day", 7); //default to Sunday
var cardStartDisplay = dtUtil.getWeekStart(created, firstDay).getDisplayValue(); //display date used in title
var cardStart = dtUtil.getWeekStart(created, firstDay).getValue(); //GlideDate
cardStart = String(RP.getParameterValue("sysparm_week_start_on"));
gs.print("CARDSTART: " + cardStart);
cardStart;
</g2:evaluate>
<g2:evaluate var="jvar_timecard_query" jelly="true">
//var query = "state=Submitted^week_starts_on=" + jelly.jvar_card_start + "^user=" + RP.getParameterValue("sysparm_user");
var query = "state=Submitted^user=" + RP.getParameterValue("sysparm_user") + "^week_starts_on=" + jelly.jvar_card_start;
//gs.print('query:' + query);
query;
</g2:evaluate>
<g2:evaluate var="jvar_title" jelly="true">
var timecard = new GlideRecord("time_card");
timecard.initialize();
var title = timecard.getClassDisplayValue() + ' (' + gs.getUserName() + " " + cardStartDisplay + ')';
title;
</g2:evaluate>
<g2:evaluate var="jvar_userid" expression="RP.getParameterValue('sysparm_user')" />
<!--<h2>jvar_userid = $[jvar_userid]</h2>-->
<table style="padding-left:2px" class="wide" cellspacing="0">
<tr class="header">
<td class="column_head" align="left">
$[jvar_title]
</td>
</tr>
</table>
<br/>
<span>
To review time cards for an individual, select an individual from the employee drop down list.
<br />
Click the Approve or Reject button after reviewing the time cards
<br/>
</span>
<g:evaluate jelly="true">
var selectedUser = String(RP.getParameterValue('sysparm_user'));
var selectedDate = String(RP.getParameterValue('sysparm_week_start_on'));
var getManager = gs.getUserID();
var sys_users = new GlideRecord("sys_user");
sys_users.addQuery("manager", gs.getUserID());
sys_users.orderBy("name");
sys_users.query();
var time_cards = new GlideAggregate("time_card");
time_cards.addQuery("state", "Submitted");
time_cards.addQuery("user.manager", gs.getUserID());
time_cards.groupBy("user");
//var query = "=^week_starts_on=" + jelly.jvar_card_start + "^user=";
//query = query + RP.getParameterValue("sysparm_user");
time_cards.query();
var time_cards_date = new GlideAggregate("time_card");
time_cards_date.addQuery("state", "Submitted");
time_cards_date.addQuery("user.manager", gs.getUserID());
time_cards_date.addQuery("user", selectedUser);
time_cards_date.groupBy("week_starts_on");
//time_cards_date.groupBy("user.manager");
time_cards_date.query();
</g:evaluate>
<j:if test="${time_cards.getRowCount() != 0}">
Please select a time card from the following employees:
<select id="UsersList" onchange="switchUsers()">
<option value="">-- None --</option>
<j:while test="${time_cards.next()}">
<j:if test="${time_cards.getValue('user') == selectedUser}">
<option value="${time_cards.user}" selected="selected">
${time_cards.user.name}
</option>
</j:if>
<j:if test="${time_cards.getValue('user') != selectedUser}">
<option value="${time_cards.user}">
${time_cards.user.name}
</option>
</j:if>
</j:while>
</select>
<br />
<j:if test="${selectedUser != ''}">
Please select a week:
<select id="WeekStartsOn" onchange="switchDates()">
<option value="">-- None --</option>
<j:while test="${time_cards_date.next()}">
<j:if test="${time_cards_date.week_starts_on == selectedDate}">
<option value="${time_cards_date.week_starts_on}" selected="selected">
${time_cards_date.week_starts_on}
</option>
</j:if>
<j:if test="${time_cards_date.week_starts_on != selectedDate}">
<option value="${time_cards_date.week_starts_on}">
${time_cards_date.week_starts_on}
</option>
</j:if>
</j:while>
</select>
</j:if>
<br/>
<!--<j:if test="${RP.getParameterValue('sysparm_user') != ''}">-->
<j:if test="${selectedUser != ''}">
<j:if test="${selectedDate != ''}">
<button id="Approve" onclick="approveTimeCards()">
${gs.getMessage("Approve Timecards")}
</button>
<button id="Reject" onclick="rejectTimeCards()">
${gs.getMessage("Reject Timecards")}
</button>
<br/><strong>Approval/Rejection Comments: </strong><br/>
<textarea id="ApprovalRejectionComments" rows="4" cols="50"></textarea>
<span id="list_span" style="display:none">
<br/>
<!--
Results from Rate Card Condition
-->
<j:if test="${!RP.isPortal()}">
<j:set var="jvar_use_name_for_list_id" value="true"/>
</j:if>
<g:list_default table="time_card" view="my_timecard"/>
<!-- Set up ListProperties for the list -->
<g:evaluate jelly="true">
var title = gs.getMessage("Time Cards");
ListProperties.setListName(title);
ListProperties.setTitle(title);
ListProperties.setListID("my_timecards");
ListProperties.setHasTopNav(true);
ListProperties.setHasTitle(true);
ListProperties.setHasTitleContextMenu(true);
ListProperties.setHasFilter(true);
ListProperties.setHasBreadcrumbs(false);
ListProperties.setHasSearch(false);
ListProperties.setHasTopVCR(true);
ListProperties.setHasHeader(true);
ListProperties.setHasHeaderContextMenu(true);
ListProperties.setHasListMechanic(true);
ListProperties.setHasRowContextMenu(true);
ListProperties.setShowLinks(true);
ListProperties.setHasPopup(true);
ListProperties.setShowEmpty(true);
ListProperties.setHasBottomNav(true);
ListProperties.setHasActions(true);
ListProperties.setHasBottomVCR(true);
ListProperties.setCanChangeView(true);
ListProperties.setCanGroup(false);
</g:evaluate>
<!-- register for list printing -->
<j:set var="jvar_handle_list_printing" value="true"/>
<!-- and build the list output -->
<g:inline template="list2_default.xml"/>
</span>
<g:evaluate var="jvar_widget_id" expression="GlideGuid.generate(this);" />
</j:if>
</j:if>
</j:if>
<!--<j:if test="${time_cards_date.getRowCount() == 0}">
No Time Cards to approve from selection
</j:if>-->
<script>
var newCards = [];
var GlideWidgetRefresh = Class.create(GlideListWidget, {
initialize: function(widgetID, listID) {
GlideListWidget.prototype.initialize.call(this, widgetID, listID);
},
_refresh: function(listTable, /*GlideList2*/ list, initialLoad) {
if (!initialLoad) {
this._showList();
this._syleRows();
}
},
_showList: function() {
show("list_span");
},
_syleRows: function() {
if (newCards.length == 0)
return;
//apply style to new cards
for (var i=0; i != newCards.length; i++) {
var rowId = "row_my_timecards_" + newCards[i];
var row = $(rowId);
if (row)
row.setAttribute("class", "new_card");
}
},
type: 'GlideWidgetRefresh'
});
new GlideWidgetRefresh('${jvar_widget_id}', 'my_timecards');
</script>
<script>
addLoadEvent( function() {
GlideList2.get("my_timecards").setDefaultFilter("$[jvar_timecard_query]");
});
function switchUsers() {
window.location.href="timecard_approval.do?sysparm_user="+ document.getElementById("UsersList").value;
}
function switchDates() {
window.location.href="timecard_approval.do?sysparm_user="+ document.getElementById("UsersList").value + "${AMP}sysparm_week_start_on=" + document.getElementById("WeekStartsOn").value;
}
function approveTimeCards() {
var ok = confirm("${gs.getMessage('Are you sure you want to approve these time cards?')}");
if (!ok)
return;
var gajax = new GlideAjax("TimecardAjaxApproval");
gajax.addParam("sysparm_name", "updateTimeCards");
gajax.addParam("sysparm_cardstart", "$[jvar_card_start]");
gajax.addParam("sysparm_user", "$[jvar_userid]");
gajax.addParam("sysparm_approval", "approve");
gajax.addParam("sysparm_comments", document.getElementById('ApprovalRejectionComments').value);
gajax.getXML(ajaxResponse);
}
function rejectTimeCards() {
if (document.getElementById("ApprovalRejectionComments").value == "")
{
alert ("Please fil out your rejection comments");
return;
}
var ok = confirm("${gs.getMessage('Are you sure you want to reject these time cards?')}");
if (!ok)
return;
var gajax = new GlideAjax("TimecardAjaxApproval");
gajax.addParam("sysparm_name", "updateTimeCards");
gajax.addParam("sysparm_cardstart", "$[jvar_card_start]");
gajax.addParam("sysparm_user", "$[jvar_userid]");
gajax.addParam("sysparm_rejectby", "${getManager}");
gajax.addParam("sysparm_approval", "reject");
gajax.addParam("sysparm_comments", document.getElementById('ApprovalRejectionComments').value);
gajax.getXML(ajaxResponse);
}
function ajaxResponse(serverResponse) {
var resultElement = serverResponse.responseXML.getElementsByTagName("result");
var countCreated = resultElement[0].getAttribute("count");
var getUserID = resultElement[0].getAttribute("userid");
newCards = resultElement[0].getAttribute("newCards").split(",");
var list = GlideList2.get("my_timecards");
//list.refresh();
alert("You have successfully processed your approval/rejection for your time cards");
var tcTotal =${time_cards_date.getRowCount()};
if (tcTotal > 1)
window.location.href="timecard_approval.do?sysparm_user=" + getUserID;
else
window.location.href="timecard_approval.do";
}
</script>
<style type="text/css">
tr.new_card {background-color:lightyellow;}
</style>
</j:jelly>
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2016 12:02 PM
I found the table where this note goes. I don't see a way to delete my original post, but I no longer need assistance with this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2016 02:33 PM
Hi Karla,
Best thing is if you dont delete your post and just have you answer here as a post and mark it as correct. Then it would be easier for others with similar problem see what you have done and hopefully solve theirs as well.
//Göran