Bat El Liav
Tera Contributor

Very simple thing, but took a while to understand the cause, so here is it.

Introduction

Reference field in a child table of incident (custom "incident details" table) with advanced reference qualifier:
find_real_file.png

The results list should contain only requests which work start is no earlier than six months prior to the creation of the incident. Therefore, the "current.sys_created_on" has been used:

    promotion_ref_qual: function() {
        var gdt = new GlideDateTime(current.sys_created_on);
        gdt.addMonths(-6);

        var answer = 'u_change_type=Marketing';
        answer += '^u_marketing_status=2^ORu_marketing_status=4';
        answer += '^work_start>=' + gdt;

        return answer;
    },

Issue

The presented qualifier worked great in the form, but while trying to update the field from the list, the query was breaking and showing 0 results.

Solution

The reply of HI support was:
"The issue here seems to be the use of "current" object.
It won't work on a list (at least for listv2; fixed in list v3, but that's not being used here and deprecated now).
As a result, it'll break the query, and thus we see the behavior on the list.
Please test by removing the use of the "current" object in the script include, as that's being called by the reference qualifier.
If you're able to get results, same as form, then we know it's due to that, and please modify accordingly as it's customization which is out of support's scope."

So, according to my check, the "current" in the form and the "current" in the list are two different objects with different sets of fields. Therefore, it didn't work. However, both contain sys_id of the relevant incident and there's no issue to get the relevant record by sys_id and then to filter as desired.
Here is the code that worked for me:

   promotion_ref_qual: function() {
		var incident = new GlideRecord("incident");
		incident.get(current.sys_id);				
		
        var gdt = new GlideDateTime(incident.sys_created_on);
        gdt.addMonths(-6);
	
        var answer = 'u_change_type=Marketing';
        answer += '^u_marketing_status=2^ORu_marketing_status=4';
        answer += '^work_start>=' + gdt;

        return answer;
    },

NOTE: It won't work in bulk, just one incident at a time. It meets the requirement for me, but if someone wants to make it work also for bulk update – you are welcome to leave a comment. 

 
Comments
ServiceNerd
Giga Guru
Giga Guru

Version history
Last update:
‎05-01-2022 04:21 AM
Updated by: