How to get all the Variables on My Todos page for approvals
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 05:23 AM
Hi community,
We have a requirement to show all the variables/fields on My todos page for all the Approvals(Req,change,knowledge,HR)
Currently using the 'Todos Approval Details Header' widget from 'Todos Requested Item Approval' widget and mapped to Request Approval Todo we are getting only two variables.
But how can we get all the variables/fields which are for the Request/change/knowledge ticket fields like below.
TIA.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 06:14 AM
why to show all variables? won't it look cumbersome if we show all variables?
Did you check those widgets?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 07:20 AM - edited ‎10-17-2023 07:23 AM
Hi @Ankur Bawiskar - I agree to your point but it was the ask from customer.
I 'm thinking to put those in a button like Expand for more details(like I have a widget to reference and I took the part which I required and kept in the 'Todos Requested Item Approval' widget. I'm able to get the button and click on it, but variables are not displaying. Below is the script which I took from another widget which have same process to show all the variables
HTML:
<div ng-click="expandCollapse()" id="expand-collapse" align="left">Expand for more Details</div>
<div class="show_form">
<fieldset disabled>
<sp-model form-model="data.f" view="catalog" mandatory="mandatory"></sp-model>
</fieldset>
</div>
CSS:
#expand-collapse{
background-color: #da291c;
border-color: #c32519;
color: White;
width: 200px;
text-align: center;
padding: 10px 0;
border-radius: 6px;
font-size: 17px;
margin: 10px 0 5px;
}
.show_form{
padding: 10px 0;
display:none;
span.h4.ng-binding {
display: none;
}
}
Client controller:
function ($scope, $animate, $rootScope) {
$scope.$watch("data.task", function() {
$scope.task = $scope.data.task; // copy for shortcuts above
});
$scope.expandCollapse = function(){
if($(".show_form").css('display') == 'none') {
$("#expand-collapse").html("Collapse");
$(".show_form").show();
} else {
$("#expand-collapse").html("Expand for more Details");
$(".show_form").hide();
}
}
}
Server Script:
(function() {Bold font on the server script is related to the variable issue which I'm mentioning. The above scripts which I've added in OOB ''Todos Requested Item Approval' instead of 'Todos Approval Details Header' . I was trying to debug why the variables are not getting populated, This I missed anything ? In logs sp.getRecord(); itself is not coming. Please Suggest
data.CONST = {
i18n: {
REQUESTED_ITEMS: gs.getMessage("Requested items"),
CATALOG_ITEMS: gs.getMessage("Catalog items"),
},
APPROVAL_TYPE: "ritm_or_req"
};
// g_approval_form_request is for approval summarizer ACLs
// that let user read a record they need to approve. This global
// variable is then deleted at the bottom of the script
(function() {
_approval_form_request = true;
var gr = $sp.getRecord();
gs.info('getgr:' + gr);
if (gr == null || !gr.isValid()) {
data.isValid = false;
return;
}
if (gr.getValue("approver") != gs.getUserID())
data.approver = gr.approver.getDisplayValue();
data.isValid = true;
var task = getRecordBeingApproved(gr);
if (task == null) {
data.isValid = false;
return;
}
var t = {};
t = $sp.getFieldsObject(task, 'number,short_description,opened_by,requested_by,start_date,end_date,quantity,price,recurring_price,recurring_frequency');
t.table = task.getLabel();
var items = [];
var idx = 0;
var itemsGR = new GlideRecord("sc_req_item");
itemsGR.addQuery("request", task.sys_id);
itemsGR.query();
if (itemsGR.next()) {
var item = {};
item.short_description = itemsGR.short_description.toString();
if (itemsGR.getValue("price") > 0)
item.price = itemsGR.getDisplayValue("price");
if (itemsGR.getValue("recurring_price") > 0) {
item.recurring_price = itemsGR.getDisplayValue("recurring_price");
item.recurring_frequency = itemsGR.getDisplayValue("recurring_frequency");
}
if (itemsGR) {
item.variables = new GlobalServiceCatalogUtil().getVariablesForTask(itemsGR, true);
item.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', {
'variables': item.variables,
'toggle': false,
'task': t.number.value
});
}
items[idx] = item;
idx++;
data.isOtherForm = false;
} else {
// Get fields of a non-RITM record.
// The "task" variable should already be a
// GlideRecord of what is being approved.
data.isOtherForm = true;
data.table = task.getTableName();
console.log('table: ' + data.table);
data.f = $sp.getForm(task.getTableName(), task.sys_id);
console.log('data fields: ' + JSON.stringify(data.f));
for (var prop in data.f._fields) {
data.f._fields[prop]["sys_readonly"] = true;
}
}
});
if (options && options.sysId) {
data.sysId = options.sysId;
data.ritmSysId = getRitmIdFromApproval(data.sysId);
data.detailsHeaderWidget = $sp.getWidget("todos-approval-details-header", {
approvalType: data.CONST.APPROVAL_TYPE,
approvalSysId: data.sysId
});
data.ritmVariablesWidget = $sp.getWidget("requested-item-variables", {
sysId: data.ritmSysId,
isExpanded: false
});
data.todoapproval = $sp.getWidget("todo-approval", {
sysId: data.sysId,
// options.useCommentBox = true;
});
data.approvalActionsWidget = $sp.getWidget("todo-approval-actions", {
sysId: data.sysId,
useCommentBox: true,
commentId: options.commentId,
commentTable: options.commentTable
});
// data.ritmTotalPrice = getPriceFromRitmId(data.ritmSysId);
}
function getRitmIdFromApproval(approvalSysId) {
var approvalGr = new GlideRecordSecure("sysapproval_approver");
if (approvalGr.get(approvalSysId)) {
if (approvalGr.document_id)
return approvalGr.document_id.toString();
else
return approvalGr.sysapproval.toString();
} else {
gs.error(gs.getMessage("Todos Requested Item: Error reading Approval record"));
return null;
}
}
function getPriceFromRitmId(ritmSysId) {
var formatter = new sn_currency.GlideCurrencyFormatter();
var ritmGr = new GlideRecordSecure("sc_req_item");
if (ritmGr.get(ritmSysId)) {
var currencyCode = ritmGr.price.getSessionCurrencyCode();
var totalPrice = formatter.format(ritmGr.getValue('price') * ritmGr.getDisplayValue('quantity'), currencyCode);
return totalPrice;
} else {
gs.error(gs.getMessage("Todos Requested Item: Error reading Requested Item record"));
return null;
}
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 09:22 PM
@Ankur Bawiskar - Does the $sp.getRecord(); work in scope application?
As we are getting the undefined in log when using this. Can you please suggest an alternative for this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2023 10:10 PM
Hi @Janu sree ,
May be you can create new tab beside activity tab and there you can add custom widget in that tab using to-do's configuration for remaining variables.
Thanks,
Akshay