Using a simple list in a portal form

PeteM1
Tera Contributor

Hello All.

 

I would like to use a simple list in a parent form and filter out it's child documents using the filter that is in the simple list widget. So, in the filter section of the parent I have tried: parent_number=javascript:$sp.getValue('sys_id'), parent_number=javascript:g_form.getValue('sys_id'), but nothing seems to work. I've hardcoded in a sys_id in the filter and that seems to work fine, however I can't seem to do it dynamically. Any thoughts/ideas?

 

I opted not to use the 'related list' feature as I didn't like the 'user experience' it provides.

4 REPLIES 4

Anand Kumar P
Giga Patron
Giga Patron

Hi @PeteM1 ,

var parentNumber = g_form.getValue('sys_id');
function setFilterForSimpleList() {
    var listWidget = g_form.getControl('your_list_widget_field_name');
    var filter = 'parent_number=' + parentNumber; // Construct your filter condition
  listWidget.filter = filter; 
    listWidget.refresh(); 
}

Thanks,

Anand

PeteM1
Tera Contributor

Hello @Anand Kumar P  and thank you for the quick response. I currently have this script running in a onload client script as below, but it does not seem to get the sys_id of the record. Should this be in an onload script..or should it be somewhere else? Thanks in advance. 

 

function onLoad() {
    //Type appropriate comment here, and begin script below
    var parentNumber = g_form.getValue('sys_id');
console.log('this is a test', parentNumber);
setFilterForSimpleList();
 
    function setFilterForSimpleList() {
        var listWidget = g_form.getControl('widget-simple-list');
console.log(listWidget);
        var filter = 'parent_number=' + parentNumber; // Construct your filter condition
        listWidget.filter = filter;
        listWidget.refresh();
    }
}
 
 

Hi @PeteM1 ,

Yes you can use it on onload client script update with below script 

var parentNumber = g_form.getUniqueValue();

 

Thanks,

Anand

PeteM1
Tera Contributor

Thanks again for the response @Anand Kumar P. After another unsuccessful attempt, it appears getControl is not supported in a Portal. So, I found this alternative (https://www.servicenow.com/community/developer-forum/embedded-sp-widget-options/m-p/1612824) and it seems to work well. The only issue I am having with it is I need it to use a recordwatcher. I am hoping that is just some sort of option I can set as part of the server side code.....