How to display change request feilds in approval widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 04:05 PM
Hello,
I am trying to edit the "approval record" widget to display 2 change request feilds (what_is_the_change_required,u_why_is the_change_required), on the approval widget on serviceportal. But it is showing on all approvals like ritm, tasks etc. Please guide me on the server side script to display this only on change request realted approvals.
Below is my ss script and html:server side script
(function() {
g_approval_form_request = true;
var gr = $sp.getRecord();
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,u_what_is_the_change_required,u_why_is the_change_requiredstart_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();
while (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.items = items;
data.sys_id = gr.getUniqueValue();
data.task = t;
// Check if the task being approved is a change record
if (task.getRecordClassName() === 'change_request') {
data.showChangeRequestFields = true;
data.variables = new GlobalServiceCatalogUtil().getVariablesForTask(task, true);
data.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', { 'variables': data.variables, 'toggle': true, 'task': t.number.value });
} else {
data.showChangeRequestFields = false;
}
var ticketConversationOptions = {
placeholder: gs.getMessage("Type your message here..."),
placeholderNoEntries: gs.getMessage("Start a conversation..."),
btnLabel: gs.getMessage("Send")
};
if (options.use_approval_record_activity_stream === true || options.use_approval_record_activity_stream === "true") {
ticketConversationOptions.sys_id = gr.getUniqueValue();
ticketConversationOptions.table = gr.getRecordClassName();
ticketConversationOptions.title = gs.getMessage("Activity Stream for Approval");
} else {
ticketConversationOptions.sys_id = task.getUniqueValue();
ticketConversationOptions.table = task.getRecordClassName();
ticketConversationOptions.title = gs.getMessage("Activity Stream for {0}", task.getLabel());
}
data.ticketConversation = $sp.getWidget('widget-ticket-conversation', ticketConversationOptions);
delete g_approval_form_request;
})();
Html:
<div ng-if="!data.isValid">
${Record not found}
</div>
<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.short_description">{{::task.short_description.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><label for="whyIsTheChangeRequired">Why is the change required:</label>
<textarea id="whyIsTheChangeRequired" class="form-control scrollable-textarea" ng-model="task.u_why_is_the_change_required.display_value" readonly></textarea></div>
<div>${why is the change required :} <input type="text" size="100" placeholder="" class="form-control" ng-model="task.u_why_is_change_required.display_value"readonly/></div>
<div>${Why is it necessary :} <input type="text" size="100" placeholder="" class="form-control" ng-model="task.u_why_is_it_necessary.display_value"readonly/></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}}
<span ng-if="task.recurring_frequency.value != null"><label>${Recurring price}</label> {{::task.recurring_price.display_value}} {{task.recurring_frequency.display_value}}</span>
<label ng-if="task.quantity && task.quantity.value > 1"> ${each}</label>
</div>
<div ng-if="data.items.length > 0">
<h3 class="h4">${Items in this Request}</h3>
<div ng-repeat="item in data.items">
<h4>
{{::item.short_description}}
</h4>
<div ng-if="item.price">${Price} {{::item.price}}
<span ng-if="item.recurring_price">${Recurring price} {{::item.recurring_price}} {{::item.recurring_frequency}}</span>
</div>
<sp-widget ng-if="item.variableSummarizerWidget" widget="item.variableSummarizerWidget"></sp-widget>
</div>
</div>
<sp-widget widget="data.variableSummarizerWidget"></sp-widget>
</div>
<sp-widget widget="data.ticketConversation"></sp-widget>
</div>
Thanks a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 06:32 AM
Hi,
were you able to solve your issue? We have a bit of similar request. we would like to add additional info for Knowledge articles approval.