Populate dashboards based on selection on the onwer variable value

akankshak15
Tera Guru

I am creating a scenario where I have to populate dashboards based on the selection of owner variable (reference to user table) value on catalog item.

I have written the script working on the background script but I am not getting how to call this script include at the reference qualifier Can someone help me with this? 

 

1 ACCEPTED SOLUTION

@akankshak15  - Use case has some exceptions as one dashboard owner can have multiple dashboards assigned.

 

However you can adjust that change later in the script includes. 

1. You need to have a on change client script on the Dashboard owner field which will call a script include where you will pass user sys id and return the dashboards sys id.

 

2. In script include you need to query pa_dashbords table putting query for the owner and return the sys id. 

 

3. After receiving the sys id in the client script just use the form set value to set the value for dashboard variable using g_form.setValue()

 

Let me know if any concerns 

 

---------------------------------------------------------------------------------------------------

Please mark my answer as helpful/correct if it resolves your query.

Thanks,
Nilesh Wahule

---------------------------------------------------------------------------------------------------

 

View solution in original post

7 REPLIES 7

akankshak15
Tera Guru

I have written a client callable script include and on change client script but not able to handle response of script include .. getting correct result when i have run the script include in background script 

Script Include:  

var populatedashBoarddata = Class.create();
populatedashBoarddata.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 dashboardData: function() {
        var dashboardIds = [];
        var userId = this.getParameter('sysparm_userId');
        if (!userId) {
            gs.error('No userId');
            return JSON.stringify({ error: 'No userId provided' });
        }

        gs.log('Received userId: ' + userId);

        var gr = new GlideRecord('pa_dashboards');
        gr.addQuery('owner', userId);
        gr.query();

        while (gr.next()) {
            dashboardIds.push(gr.getUniqueValue());
        }

        gs.log('Fetched dashboardIds: ' + dashboardIds);

        return dashboardIds;
    },
    type: 'populatedashBoarddata'
});
 
 
Client Script : 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    if (newValue) {
        var ga = new GlideAjax('populatedashBoarddata');
        ga.addParam('sysparm_name', 'dashboardData');
        ga.addParam('sysparm_userId', newValue);

        ga.getXMLAnswer(callBack);
    }
            function callBack(response){
       
                var res = JSON.parse(response);

                for( var i=0 ; i < res.length ; i++) { //Loop into the array
                           g_form.addInfoMessage(res[i]);
                              g_form.setValue('dashboard', res[i]);
                }
               
           
        };
    }


Nilesh Wahule
Tera Guru

Hey @akankshak15 ,
Can you provide more context for use case ?

I wanted to populated dashboards name in the variable , based on selection of the 'Dashboard owner' variable value 

ex. if i will select Abel in 'Dashboard Owner ' variable then in 'Dashboard ' variable all the dashboard name should populate where Able is owner of the dashboard

@akankshak15 - What you want to have a reference dynamically based on the owner selected.

 

You have a variable called "Dashboard" on the catalog item along with one more field as "Dashboard Owner", so whenever the Dashboard owner is changed, you need to show auto populate the dashboard variable. 

Is my understanding correct ?