onChange client script to call UI Macro, but group by incident state - similar to "user_show_incidents"

dustinevans
Tera Contributor

Customer Support Manager is wanting a pop-up to show a list of incidents for the selected caller. So when a tech enters the customers name in the caller_id field, a report will pop-up grouping that customers Incidents by the Incident state. We basically want to want to use the existing UI Macro "user_show_incidents", but group by the incident state. We then want to trigger that UI Macro when the "caller_id" field changes, so I assume we would use an onChange client script.

I created a copy of the UI Macro and tried modifying it but I cant get it to group by the Incident State. I can create a chart on the incident form and group by state but since list reports aren't supported, that only helps a little. That still requires the technician to click the bar to open a list of the incidents.

I am very green when it comes to scripting but consider myself resourceful. I just cant seem to figure this out.I have tried combining the existing function and using GlideAggregate with no luck. I would think this wouldn't be too hard but at this point I have run out of ideas and spending too much time . Any guidance is appreciated. 

1 ACCEPTED SOLUTION

Manish Vinayak1
Tera Guru

Hi Dustinevans,

 

If you want a popup on change of the caller_id, you won't need to create a new UI Macro. The UI macro "user_show_incidents" actually triggers internal logic (hidden UI page maybe) called "show_list", and you won't be able to see the code written for that.

You can have the following code in your onChange client script, which triggers on change of the "Caller ID" field:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var displayValue = g_form.getValue("sys_display.incident.caller_id");
	var title = 'Showing records related to: ' + displayValue;
	var query = 'caller_id=' + g_form.getValue("caller_id");
	var gdw = new GlideModal('show_list');
	gdw.setTitle(title);
	gdw.setSize(750);
	gdw.setPreference('focusTrap', true);
	gdw.setPreference('table', 'incident_list');
//Adding ^GROUPBYstate to the existing query you can add ^GROUPBYincident_state if that's what you need
	gdw.setPreference('sysparm_query', query + "^GROUPBYstate");
	gdw.setPreference('title', 'A New Title');
	gdw.render();
	
}

 

Here's the result of my client script:

find_real_file.png 

You will see that I am using the same code present in "user_show_incidents" ui macro, but just adding additional parameter for grouping the incidents by state. Just appending ^GROUPBYstate to the existing query parameter does the trick.

Hope this helps!

Cheers,

Manish

View solution in original post

3 REPLIES 3

Manish Vinayak1
Tera Guru

Hi Dustinevans,

 

If you want a popup on change of the caller_id, you won't need to create a new UI Macro. The UI macro "user_show_incidents" actually triggers internal logic (hidden UI page maybe) called "show_list", and you won't be able to see the code written for that.

You can have the following code in your onChange client script, which triggers on change of the "Caller ID" field:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
	var displayValue = g_form.getValue("sys_display.incident.caller_id");
	var title = 'Showing records related to: ' + displayValue;
	var query = 'caller_id=' + g_form.getValue("caller_id");
	var gdw = new GlideModal('show_list');
	gdw.setTitle(title);
	gdw.setSize(750);
	gdw.setPreference('focusTrap', true);
	gdw.setPreference('table', 'incident_list');
//Adding ^GROUPBYstate to the existing query you can add ^GROUPBYincident_state if that's what you need
	gdw.setPreference('sysparm_query', query + "^GROUPBYstate");
	gdw.setPreference('title', 'A New Title');
	gdw.render();
	
}

 

Here's the result of my client script:

find_real_file.png 

You will see that I am using the same code present in "user_show_incidents" ui macro, but just adding additional parameter for grouping the incidents by state. Just appending ^GROUPBYstate to the existing query parameter does the trick.

Hope this helps!

Cheers,

Manish

That did the trick.

I figured it was simple but I just couldn't wrap my head around it. On the plus side, I learned a bunch about creating UI pages, macros, and charts on records.

Thanks a bunch Manish!!!

Glad that it worked!

Learning new things is always great 🙂

Cheers,

Manish