Passing catalog item variables to data table from URL filter

Bradley Owens
Tera Contributor

Hi everyone.

 

I have an ask to make a list view of one of our custom tables that shows what access a customer has.  I've been able to adjust the oob data table from URL widget to display but I cannot figure out how to pass the user name entered into the catalog item to the widget filter.  I had set up a client script that creates an event for the widget to listen for so that it could grab the variable and pass it to the widget to use in the filter.  Here is what I have:

 

Client script on the catalog item:

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var requestorSysId = g_form.getValue('requestor'); // This gets the sys_id of the selected user
    if (window.CustomEvent && window.dispatchEvent) {
        var event = new CustomEvent('requestorChanged', {
            detail: {
                requestorSysId: requestorSysId
            }
        });
        window.dispatchEvent(event);
    }
}

 

Part of my server script for the widget:

 

 // widget parameters
			var requestorSysID = input.requestorSysID;
            data.table_label = gr.getLabel();
            data.fields = $sp.getListColumns(data.table, data.view);
            copyParameters(data, ['p', 'o', 'd', 'filter', 'fixed_query']);
            copyParameters(data, ['relationship_id', 'apply_to', 'apply_to_sys_id']);
            data.filterACLs = true;
            data.show_new = true;
            data.show_keywords = false;
            data.show_breadcrumbs = true;
            data.fromUrl = true;
            data.filter = 'revoked_byISNOTEMPTY^u_user_name=' + requestorSysID;
            data.useInstanceTitle = (options.use_instance_title == "true");
            data.headerTitle = data.useInstanceTitle ? options.title : gr.getPlural();
            data.enable_filter = input.enable_filter || options.enable_filter == true || options.enable_filter == "true";
            data.dataTableWidget = $sp.getWidget('widget-data-table', data);

 

 

And what I added to the client controller for the widget:

 

if (window.addEventListener) {
    window.addEventListener('requestorChanged', function(e) {
        var requestorSysId = e.detail.requestorSysId;
        // Use this sys_id to update the widget
        $scope.server.update({requestorSysId: requestorSysId});
    });
}

 

My scripting is extremely weak and I had help to get this far but I'm not sure what I'm messing up

3 REPLIES 3

SanjivMeher
Mega Patron

Can you add this to your server script

 

 // widget parameters
			var requestorSysID = input.requestorSysID;
            var user = new GlideRecord('sys_user');
            user.get(requestorSysID);
            data.table_label = gr.getLabel();
            data.fields = $sp.getListColumns(data.table, data.view);
            copyParameters(data, ['p', 'o', 'd', 'filter', 'fixed_query']);
            copyParameters(data, ['relationship_id', 'apply_to', 'apply_to_sys_id']);
            data.filterACLs = true;
            data.show_new = true;
            data.show_keywords = false;
            data.show_breadcrumbs = true;
            data.fromUrl = true;
            data.filter = 'revoked_byISNOTEMPTY^u_user_name=' + user.user_name;
            data.useInstanceTitle = (options.use_instance_title == "true");
            data.headerTitle = data.useInstanceTitle ? options.title : gr.getPlural();
            data.enable_filter = input.enable_filter || options.enable_filter == true || options.enable_filter == "true";
            data.dataTableWidget = $sp.getWidget('widget-data-table', data);

Please mark this response as correct or helpful if it assisted you with your question.

That just gives me back the user name=(empty).  I don't think it's passing the user from my requestor field to my widget still.

Can you change the script in Client controller to 

 

function($rootScope, $scope, $timeout, $location, $log, $window, spUtil, nowAttachmentHandler, spAriaUtil, spNavStateManager) {
        var c = this;
    $scope.$watch('requestorChanged', function(newVal, oldVal) {
        if (newVal) {
            c.data. requestorSysID = newVal;
			
            c.server.update().then(function() {
                c.data. requestorSysID = "";
            })
			
        } 
    });
}

Please mark this response as correct or helpful if it assisted you with your question.