How to show workflow stage in ticket widget RITM Service Portal?

zulhiyatiuwi
Tera Expert

Hello, how can i add information about stage in ticket page portal?

I want to show this stage from RITM list to portal

find_real_file.png

Portal, how can i do this? Please help...

find_real_file.png

 

1 ACCEPTED SOLUTION

zulhiyatiuwi
Tera Expert

Hello, I have found way to show stage in ticket. I cloned Request Items widget and change script in Server Script line 9 and 31

(function() {
	/*var rec = $sp.getRecord();
	if (rec != null && rec.isValid())
		data.conversation_title = rec.getDisplayValue();
	if (!data.conversation_title)
		data.conversation_title = gs.getMessage("Request");*/
	
	data.title = options.title || gs.getMessage("Stage");
	var gr = new GlideRecord("sc_req_item"); // does ACL checking for us
	gr.addQuery("sys_id", $sp.getParameter("sys_id"));//gr.addQuery("request", $sp.getParameter("sys_id"));

	options.secondary_fields = options.secondary_fields || "number";
	options.secondary_fields = options.secondary_fields.split(",");

	if (options.order_direction == "asc")
		gr.orderBy(options.order_by);
	else
		gr.orderByDesc(options.order_by);

	if (options.maximum_entries > 0)
		gr.setLimit(options.maximum_entries);
	gr.query();

	data.actions = [];
	data.list = [];
	while (gr.next()) {
		if (!gr.canRead())
			continue;
      
		if (gr.getRowCount() == 1)
			data.conversation_title = gr.getValue("short_description");//data.conversation_title = gr.getDisplayValue() + " - " + gr.getValue("short_description");

		var record = {};

		record.sys_id = gr.sys_id.getDisplayValue();
		if (options.image_field) {
			record.image_field = gr.getDisplayValue(options.image_field);
			if (!record.image_field)
				record.image_field = "/noimage.pngx";
		}
		if (options.display_field)
			record.display_field = gr.getDisplayValue(options.display_field);

		record.secondary_fields = [];
		options.secondary_fields.forEach(function(f) {
			var secondaryField = getField(gr, f);
			if (secondaryField != null)
				record.secondary_fields.push(secondaryField);
		});

		if (options.sp_page_dv)
			record.url = "?id="+options.sp_page_dv+"&table="+options.table+"&sys_id="+record.sys_id+"&view=sp";
		else
			record.url = "";

		record.stage = gr.getValue("stage");

		// get appropriate Stage choices for this requested item
		record.stageWidget = $sp.getWidget("cb6631d39f2003002899d4b4232e7030", {req_item_id: record.sys_id, onload_expand_request_item_stages: options.auto_expand_request_item_stages});

		data.list.push(record);
	}

	if (gr.getRowCount() > 1)
		data.conversation_title = gr.request.getDisplayValue() + " - " + gr.getRowCount() + " items";

	function getField(gr, name) {
		var f = {};
		f.display_value = gr.getDisplayValue(name);
		f.value = gr.getValue(name);
		var ge = gr.getElement(name);
		if (ge == null)
			return null;

		f.type = ge.getED().getInternalType();
		f.label = ge.getLabel();
		return f;
	}

})();

And now, stage is show in ticket field, actually there is error like this after i add the new widget

find_real_file.png

 

But after reload it, its gone. I dont know why 😞find_real_file.png

 

View solution in original post

5 REPLIES 5

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

please check the following thread, larstange explained a good solution on how to re-use this part of the code in other widgets, it should work fine:

https://community.servicenow.com/community?id=community_question&sys_id=f62a8f69db5cdbc01dcaf3231f96...

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

thank you for your advice. 😄

swathi52
Tera Expert

Hi 

You can do this by customizing existing widget (ticket_fields).

where you can set a variable with the value of parent request stage in server script, and use the variable in HTML part to display it on ticket page.

Thanks,

Swathi

Thank you for answering my qustion. I prefer cloned and edit request item widget. I dont know script well, so i just try another way even its show error in the first and i dont know why. 😞