Database view of catalog items where related SCTASK there's no SLA attached

Carol2
Tera Contributor

Hi All 

 

I created a database view using the task_sla and sc_task table. Both tables have the fields that I want to report on. I am stuck on joining the tables together to get the information I am looking for. Where the related SCTASK must give me the name of the catalog item and report on whether the task SLA field is populated or not. Please help i am new to creating database views 

 

Carol2_0-1734442214128.png

 

 

Carol2_2-1734442279196.png

 

 

Carol2_1-1734442505984.png

 

 

 

24 REPLIES 24

@Ankur Bawiskar no records still 

 

Carol2_1-1734515026494.png

 

 

script include: 

Line 4 might be an issue/ if I add that line there are no errors, but no records show for my report 

Carol2_0-1734514936390.png

 

 

@Carol2 

you didn't create script include as per my screenshot

it should be classless script include

copy this as it is

Name: getRecords

function getRecords() {
    var catItemArr = [];
    // Initialize GlideRecord for Catalog Task (sc_task)
    var taskGR = new GlideRecord('sc_task');
    taskGR.query();
    while (taskGR.next()) {
        // Initialize GlideRecord for Task SLA (task_sla)
        var slaGR = new GlideRecord('task_sla');
        slaGR.addQuery('task', taskGR.sys_id);
        slaGR.query();
        // Check if there are no SLA records for the task
        if (!slaGR.hasNext()) {
            catItemArr.push(taskGR.request_item.cat_item.sys_id.toString());
        }
    }
    return catItemArr.toString();
}

AnkurBawiskar_0-1734515711631.png

 

 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

Updated the script see below, still no records show 

Carol2_0-1734516427388.png

 

Carol2_1-1734516570928.png

 

@Carol2 

did you try running the script in scripts background and see if any values got printed in that array?

do you have any catalog item under which sc_task has no SLA?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

yes, we do have SCTASK with no SLA 

Carol2_0-1734531276607.png

gs.log('Carol test Catalog Item Array: ' + catItemArr.toString()); 
I ran the background script, no records are showing in the logs