Filter chart via cross site lookup field values

Hi,
I’m trying to follow the example here: 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]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]));
    }
}

}[/code]

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

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.

Try to modify this condition by comparing with 0:

if ($('#key-principals option').length == 0) { ... }

Changed 1 to 0 in the condition, still the drop down does not populate values.

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.

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.

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?

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.