Need help on Filter in Simple List to display task(s) associated with a RITM

rishabh31
Mega Sage

Dear Team,

 

This is related to a similar ask posted earlier, refer to the below URL-

https://www.servicenow.com/community/developer-forum/simple-list-to-display-task-associated-with-a-r...

 

Requesting help on the Filter field of the Simple list widget (screenshot highlighted section) so that it displays only those task(s) associated with a RITM when the user access Service Portal> My Requests-RITMXXXXXX.

 

Currently, I applied the filter 'request_itemISNOTEMPTY' filter on the sc_task table but it displays all Tasks in the instance, which is not desired.

rishabh31_0-1682068886850.png

Please help on this

 

Thank you

3 ACCEPTED SOLUTIONS

Hello @rishabh31 ,

 

So, I used the Widget "Data Table from Instance Definition" and used the "Clone Widget" UI Action

Joshua_Quinn_0-1682294718595.png

 

Then, in the clone, I updated the Server script to enhance my filter (in my use case, I was looking at Catalog Tasks tied to RITMs, so my script update occurred at around line 25, where I added the filter for the sys_id of the current record to the filter on the data table. I then check to see if there is a filter from the widget itself. If not, then the word "Null" would be present and I forgo adding it:

Joshua_Quinn_1-1682295168343.png

 

Finally, I add the widget to the page and then set the table and fields I want on the table. If you want a custom filter, you can set it due to the filter check we did on line 35 and it will append that filter here.

View solution in original post

BharathChintala
Mega Sage

@rishabh31  Simple list won't work in this scenario

 

In Standard ticket configuration

 

you can add new tab called Tasks configure accordingly.

 

Below is OOB custom one created wm_order table to get their tasks.

Similarlly you can do for Requested item as well

BharathChintala_0-1682339878163.png

 

 

BharathChintala_1-1682339878449.png

 

 

 

BharathChintala_2-1682339878146.png

 

They used "Work order Tasks for Work Order" widget we have to create one new widget replicate same for sc_tasks.

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

View solution in original post

Terribly sorry @rishabh31 ,

 

I should have realized my mistake when sending you the screenshots. I had a bug in my code. On line 27 of your server script, it should read:

data.filter = "request_item=" + sys

without that "=" the filter will fail, which is what is happening. Please try that and let me know your results.

 

Thanks!

 

View solution in original post

16 REPLIES 16

Hello @rishabh31 ,

 

So, I used the Widget "Data Table from Instance Definition" and used the "Clone Widget" UI Action

Joshua_Quinn_0-1682294718595.png

 

Then, in the clone, I updated the Server script to enhance my filter (in my use case, I was looking at Catalog Tasks tied to RITMs, so my script update occurred at around line 25, where I added the filter for the sys_id of the current record to the filter on the data table. I then check to see if there is a filter from the widget itself. If not, then the word "Null" would be present and I forgo adding it:

Joshua_Quinn_1-1682295168343.png

 

Finally, I add the widget to the page and then set the table and fields I want on the table. If you want a custom filter, you can set it due to the filter check we did on line 35 and it will append that filter here.

Hello @Joshua_Quinn Sir,

Thank you for your response, I tried the way and halfway approached it as well but could not display only the task(s) associated with respective RITM as currently, it's displaying all the tasks. (below screenshot for reference)

rishabh31_0-1682336459885.png

I want only associated task(s) to display like in this case, RITM0010046 has only 1 task-SCTASK0010006 (shown in RITM record screenshot below)

rishabh31_1-1682336627150.png

Please find below the screenshots of cloned Data table widget Server Script customization (rest script kept as it is) as advised by you

rishabh31_2-1682336725533.png

Also below is the snapshot of the cloned widget instance with a table in Designer where I am not keeping any filter.

rishabh31_3-1682337058267.png

Could you please help to only filter the associated task(s) of related RITM0010046 has only 1 task-SCTASK0010006 so displays only SCTASK0010006, the same dynamically for all other RITMs.

 

Thank you

Terribly sorry @rishabh31 ,

 

I should have realized my mistake when sending you the screenshots. I had a bug in my code. On line 27 of your server script, it should read:

data.filter = "request_item=" + sys

without that "=" the filter will fail, which is what is happening. Please try that and let me know your results.

 

Thanks!

 

Hi @Joshua Quinn Sir,

Thank you, below change in the Server script of cloned widget of the Data table from instance definition makes this work as expected.

data.filter = "request_item=" + sys

 Now the Server Script for the cloned widget named 'Copy of Data Table from Instance Definit'

it looks like below:

(function() {
    /*  "use strict"; - linter issues */
    // populate the 'data' object
    var sp_page = $sp.getValue('sp_page');
    var pageGR = new GlideRecord('sp_page');
    pageGR.get(sp_page);
    data.page_id = pageGR.getValue("id");
    $sp.getValues(data);
    if (data.field_list) {
        data.fields_array = data.field_list.split(',');
    } else {
        data.field_list = $sp.getListColumns(data.table);
    }

    if (input) {
        data.p = input.p;
        data.o = input.o;
        data.d = input.d;
        data.q = input.q;
    }
    data.p = data.p || 1;
    data.o = data.o || $sp.getValue('order_by');
    data.d = data.d || $sp.getValue('order_direction');

    //Set filter based on the record sys_id//
    var sys = $sp.getParameter('sys_id');
	data.filter = "request_item=" + sys;
	//------------------------------------//

   data.page_index = (data.p - 1);
   data.window_size = $sp.getValue('maximum_entries') || 10;
   data.window_start = (data.page_index * data.window_size);
   data.window_end = (((data.page_index + 1) * data.window_size));
   //Add the and to the filter if the filter hasn't been added yet//
   var custom_filter = '^' + $sp.getValue('filter');
   if (!custom_filter.toLowerCase().contains('null')) {
       data.filter = data.filter + custom_filter;
   }
   //--------------------------------------//
   //data.filter = $sp.getValue("filter");
   //-------------------------------------//

    var gr = new GlideRecordSecure(data.table);
    if (!gr.isValid()) {
        data.invalid_table = true;
        data.table_label = data.table;
        return;
    }
    data.table_label = gr.getLabel();

    options.table = data.table;
    options.fields = data.field_list;
    options.o = data.o;
    options.d = data.d;
    options.filter = data.filter;
    options.window_size = data.window_size;
    options.view = data.view;
    options.useInstanceTitle = true; // to make sure Data Table widget uses headerTitle always
    options.headerTitle = options.title;
    options.show_breadcrumbs = true;

    data.dataTableWidget = $sp.getWidget('widget-data-table', options);
})();

Thanks for the solution. Marking as correct

Hey Josh,

Thanks for the wonderful solution but i don't know why its not working for me, even i can't see any list of catalog task.

Santoshi5_0-1684441112767.png

i don't see the table field configuration so that i can select the table name

Santoshi5_1-1684441248225.png