Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Adding Requested for from my approvals widget service portal

Vibha19
Tera Contributor

Hi All,
Please provide a Solution solution for Adding Requested from my approvals widget service portal

 

Vibha19_1-1739285119420.png

 





1 REPLY 1

Brian Lancaster
Kilo Patron

After looking at the Approval Record widget I noticed something. It is looking for a field called requested_by. This is most likely due to the fact that requested_by is used on all other tables except requests for the person that requested it. You would have to clone the widget an change a couple of lines of code and then use that code on your page that display the approval record. I think the below modification will work without loosing requested_by for items that use that.

HTML body added:  <div ng-if="task.requested_for"><label>${Requested_for}</label> {{::task.requested_for.display_value}}</div>

<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="task.requested_for"><label>${Requested_for}</label> {{::task.requested_for.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 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>

 

Server script: added requested_for

(function() {
	// 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
	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,requested_for,start_date,end_date,quantity,price,recurring_price,recurring_frequency'); //added requested_for
	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;
	if (task) {
		data.variables = new GlobalServiceCatalogUtil().getVariablesForTask(task, true);
		data.variableSummarizerWidget = $sp.getWidget('sc-variable-summarizer', {'variables' : data.variables, 'toggle' : true, 'task': t.number.value});
	}

	function getRecordBeingApproved(gr) {
		var approvalTargetRecord;
	  if (!gr.sysapproval.nil())
			approvalTargetRecord = gr.sysapproval.getRefRecord();
		else
			approvalTargetRecord = gr.document_id.getRefRecord();

		return (approvalTargetRecord.canRead()) ? approvalTargetRecord : null;
	}

	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;
})();