Filter chart via cross site lookup field values

by MohamedGaafar » Tue Jun 21, 2016 1:31 am

Hi,
I'm trying to follow the example here: http://www.spchart.com/demo/helpdesk-dashboard/config
but instead of filtering my charts by users (agents) i'm trying to use CSL field on my list with an internal name "KeyPrincipal", however the drop down list is not populating, below is the code i'm using, appreciate your help.

Code: Select all
var handlers = {};
handlers.requestInit = function (query, logger) {
    var view = query.get_viewXml();
 
    var accountId = $('#key-principals').val();
 
    if (accountId && accountId !== '0') {
        view = view.replace('{Filter}', '<And>\
    <Eq>\
        <FieldRef Name ="KeyPrincipal" />\
        <Value Type="Lookup">' + accountId + '</Value>\
    </Eq>\
    <Neq>\
        <FieldRef Name="RecordType" />\
        <Value Type="Choice">Variant</Value>\
    </Neq>\
    </And>');
    } else {
 
        view = view.replace('{Filter}', '<Neq>\
        <FieldRef Name="RecordType" />\
        <Value Type="Choice">Variant</Value>\
    </Neq>');
    }
 
    logger.info(view);
    query.set_viewXml(view);
 
    return true;
}
 
handlers.requestSuccess = function (data, logger) {
    populateKeyPrincipals(data);
    return true;
}
 
handlers.aggregationSuccess = function (data, logger) {
    return true;
}
 

handlers.finish = function (data, logger, processor, el) {
    logger.debug('Data is processed: ', data);
 
    if (processor && !processor.subscribed) {
        $('#key-principals').change(function () {
            el.empty().html('<img alt="loading..." src="/_layouts/15/images/gears_anv4.gif" />');
            processor.process(el);
        });
 
        processor.subscribed = true;
    }
 
    return true;
}
 
function populateKeyPrincipals(data) {
    if ($('#key-principals option').length == 1) {
        var principals = {};
 
        $.each(data.items, function () {
            if (!principals[this.KeyPrincipalId]) {
                principals[this.KeyPrincipalId] = this.KeyPrincipal;
            }
        });
 
        for (var key in principals) {
            $('#key-principals').append($('<option></option>')
                   .attr('value', key)
                   .text(principals[key]));
        }
    }
}
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by Dmitry Kozlov » Wed Jun 22, 2016 8:39 am

Hi,
Your code looks right. First, ensure that you're using the correct internal name of the lookup field (KeyPrincipal).

Next, ensure that the returning data is not empty by typing in the console (in the Data Source tab):
data.items[0].KeyPrincipal
data.items[0].KeyPrincipalId
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

by MohamedGaafar » Wed Jun 22, 2016 3:13 pm

Thanks for your response,
I tested with both console entries you suggested and both returned valid values, however still the drop down is not populating.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by Dmitry Kozlov » Wed Jun 22, 2016 4:17 pm

Try to modify this condition by comparing with 0:
Code: Select all
if ($('#key-principals option').length == 0) {
    ...
}
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

by MohamedGaafar » Wed Jun 22, 2016 4:50 pm

Changed 1 to 0 in the condition, still the drop down does not populate values.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by Dmitry Kozlov » Thu Jun 23, 2016 9:33 am

Try to debug the code by inserting 'console.log' functions into populateKeyPrincipals to make sure that the code is executed. Our support team can help you with the case. Purchase 100 support minutes in our store:
https://plumsail.com/sharepoint-dashboard-designer/store/#!/100-minutes/p/17765967/category=11274284

and provide temporary access to your site.
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm

by MohamedGaafar » Thu Jun 23, 2016 12:30 pm

Alright thanks for your help, i got it working when i changed the condition to evaluate against 2 not 0 nor 1, i'm not sure why this happened although i have only 1 default entry in my drop down "All Key Principals", but it worked at 2.
User avatar
MohamedGaafar
 
Posts: 22
Joined: Sat Jan 23, 2016 12:17 pm

by lijupnandanan » Thu Sep 01, 2016 5:14 am

Hi,
I had a list in the root site that Podium Placement. the List have three fields Company,Project and Tender Amount.

I need a graph inside every projects, which lists the company and tender amount of the current projects. The graph will place inside a subsite of project , that need to be list only that projects, tender amount. No need of display all company and tender amount. How can resolve this?

I checked this link http://www.spchart.com/demo/helpdesk-dashboard/config. But haw can I get the current website's ID (list Item ID) from website properties?
Last edited by lijupnandanan on Fri Sep 09, 2016 5:23 pm, edited 1 time in total.
lijupnandanan
 
Posts: 11
Joined: Thu Sep 01, 2016 5:04 am

by Dmitry Kozlov » Thu Sep 01, 2016 10:03 am

Hi,
You can retrieve current site's ID and the title from _spPageContextInfo JS-variable. Our support team can assist you with the task. If you're interested, send the detailed description of your chart to support@spchart.com and we will estimate it.
User avatar
Dmitry Kozlov
 
Posts: 129
Joined: Wed Nov 12, 2014 3:24 pm


Return to Dashboard Designer for SharePoint 2013