Custom Attributes

I have created some custom attributes that I would like to retrieve/set values for on different dashboards.
For instance I have one called “SAVED_PERSONALIZATION_VIEWS” where I am going to add some JSON which I will later use to parse and apply some specific functionality to a dashboard.

In this article: https://www.dundas.com/support/support-center/support-articles/data-connectors/using-custom-data-and-custom-attributes-to-filter-ssas-data

I see that I can use a method called “GetCustomAttributeValues(ATTRIBUTE_NAME_HERE);” but that seems available only on the C# side of things and not javascript.

I am wondering if there is a way for me to refer to a custom attribute in the manner above and what would be the proper way of setting it’s value in the case that I can do something like that.

Thanks,
Diego

Hi Diego,

The method in the article that you are referencing is server side code typically used when you build your own data connector. In your case if you want to access your custom attributes on the client side through JavaScript, it’s readily available on your dashboards by using the following:

dundas.context.currentSession.customAttributes

Yes I have found that as well but I can’t refer to it by name but rather ID which is going to be a little tricky as I move code across environments. I am wondering if there is a way for me to go ahead and refer to the attribute by name which is what the server side code seems to give?

You can look up all of the custom attributes on your system using the CustomAttributeService. This sample code will find the first custom attribute and give you the name.

var service = this.getService(“CustomAttributeService”);
var def = service.getCustomAttributes();
def.done(function(e)
{
var customAtrributeName = e[0].value.name; // you can find the name of the attributes here
});

Here is the documentation for your reference - https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/account/CustomAttributeService/cindex.html

cheers.
jeff

1 Like

I’m using your code. I had to modify it slightly, because the quotes here weren’t accepted by the script editor; however, it’s just returning an error:

TypeError: Cannot read property ‘getCustomAttributes’ of null

Any idea?

Hi Danny,

It looks like you service object is null from some reason, where are you adding this code?

Could this code be inside a method where .this is not defined?
Maybe you have a scoping issue where .this is available? Try this .bind(this) if so…
https://codeburst.io/understanding-that-and-bind-8778f779b149

You are correct about the quotations, I had to change them back when i tested this code in a button on a dashboard but otherwise it worked perfectly.

Also, use the debugger; command in your code to pop the browser debugger tools and see what is happening. (must have F12 open if Chrome or whatever it is for other browsers)

hope this helps.

I did end up getting this. Thanks for your help Jeff. Here’s a sample of the code I used:

var dashboard = this;

var regStatus = window.dundas.context.currentSession.customAttributes[1].value.values[0].toString();

console.log(regStatus);

So, now my question is, how do I write back to that value? Let’s say the value gives me a 1, but I want it to be a 2. Thx.

Hi Danny,

I don’t believe there is a JavaScript method for writing back a custom attribute on the dashboard as these are typically tied to security. Since a custom attribute is tied to security, you wouldn’t want a user to be able to update these with a simple JavaScript update. I believe the only method is to use the REST api to make such an update programmatically.

Note: you’d need admin privileges to do this

@danny.theriault Danny, because of this restriction on custom attributes, we ended up using the AccountService.writeUserData and AccountService.getUserData methods instead. Hope this helps

https://www.dundas.com/support/api-docs/js/Content/API%20Reference/dundas/account/AccountService/cindex.html

1 Like

Is there any chance you can give me some code examples, writing back that way? Thx.

Here’s one from our support site:

https://www.dundas.com/support/developer/script-library/services/custom-attribute-service/adding-custom-attributes

@danny.theriault Sure. Of course, it all depends on your use case, but these two functions should give you an idea of what we did.

window.setCustomAttribute = function(customAttribute){
let accountService = dundas.context.getService(“AccountService”);
return accountService
.writeUserData(dundas.context.currentSession.accountId, dundas.context.baseViewViewService.currentView.id, JSON.stringify(customAttribute))
.then(function (resp){ return resp;});
}

window.getCustomAttribute = function(){
let accountService = dundas.context.getService(“AccountService”);
return accountService
.getUserData(dundas.context.currentSession.accountId)
.then(function(customAttributes){
return customAttributes.filter(function(attribute) {
return attribute.key === dundas.context.baseViewViewService.currentView.id;
});
});
}

2 Likes

Thank you. Do you know if this requires admin rights? I’m guessing so.

@danny.theriault It does not. That is why we ended up using this vs customAttributes.

Hi

I’ve also run into the fact that custom attributes cannot be changed by non-admin users, when I want to change them to track what the users have done. I will also go down the writeUserData and getUserData routes suggested by @carlos.fares

This seems to be a hidden feature, so I have a few questions.

  1. Is it possible to view this user data from the UI? I’m thinking that not everyone on the support side will be able to script to get this information.
  2. Is this data exported with the user accounts?
  3. Can I rely on Dundas not changing these values itself?

Thanks

Hi @david.glickman,

I think the best way to approach saving user data is to use the writeback that is built into the application (Data Input). You can create a data cube that will hold all of your data and have a column that stores something identifying about the user. The benefit here is that a data cube goes through the data model and can be easily visualized any way you need.

I’ve taken this writeback idea as far as building a full user based bookmark system in Dundas BI. In the visualization below, we are listing all dashboards in a folder and the user can click on the favourite cell to add a star and move the dashboard to the top. What is happening behind the scene is that we are writing back to a data cube using data input to store dashboards that are currently favourited.

Here’s my code:

var args = dundas.Utility.getAdapterHitTestArguments(e.originalEvent, table1);
var hitTestResult = table1.control.hitTest(args.offsetX, args.offsetY, args.target);
var rowIndex = hitTestResult.rowIndex;
var colIndex = hitTestResult.colIndex;

// check if the favourite is already set
if (table1.metricSetBindings[0].dataResult.cellset._rows[rowIndex].members[0].caption != "True") {
    var dashboardId = table1.metricSetBindings[0].dataResult.cellset.rows[rowIndex].members[4].caption;
    var inputService = dundas.context.getService("DataInputService");
    var def = inputService.insertDataStorageRecord("28c4db73-6b38-46f2-8ada-283063d5a50e", "abac74f0-8b37-4a87-aefd-693409d1709b", [dashboardId.toString(), true]);

    def.done(function (message) {
        // after writeback, reload the table
        table1.loadData();
    });
} else {
    var recordId = table1.metricSetBindings[0].dataResult.cellset.rows[rowIndex].members[5].caption;
    var inputService = dundas.context.getService("DataInputService");
    var def = inputService.deleteDataStorageRecord("28c4db73-6b38-46f2-8ada-283063d5a50e", "abac74f0-8b37-4a87-aefd-693409d1709b", recordId);

    def.done(function (message) {
        table1.loadData();
    });
}

As you can see this would have all the elements that you need when it comes to writing and getting user data without editing any user information with the added benefit of being able to visualize the results.

I did a video covering the concept of writeback if that helps too.

https://www.dundas.com/resources/off-the-charts-tips-from-an-expert/adding-writeback-capabilities-dashboard

1 Like

Hi Jeff

Yes, I have used this before as well, but it’s not as simple to setup, use or reuse.

You need to setup the cube with the input, pull and parse the correct data from the cube, secure other users from modifying other entires, give users writeback permissions. And then you can’t reuse the setup, or code that involves ids, on another project.

I really would like users to be able to modify their custom attributes if allowed to by the admin, or just use something on the account. Much simpler. Especially if it’s just to track a user-set preference or if they’ve performed a particular action.

Hi @david.glickman,

I see what you are saying but modifying custom attributes is never going to happen as it’s directly tied to user security. I can’t imagine a world where our team allows users to write their own custom attributes or else they could essentially write their own security privileges as the primary purpose of these attributes are to secure data. Even if editing custom attributes was allowed as an option, it’s still a potential security hole as a user could accidently have it open without realizing it.

The other problem with storing data on the account is that it isn’t part of the data model which makes it very difficult to work with when it comes to visualizing that data.

Maybe a concept of “User Preferences” would make an interesting feature request? This would keep Custom Attributes clean and secure while giving an option to store quick data. I still have questions of how you might visualize this data if needed though…

Hi Jeff

I don’t really need to visualise it, just use it in scripts and edit it in the account/group section of the admin. It’s just a bunch of strings tied to a specific key.

e.g. has the logged in user changed their password? Have they been shown a warning message? Do they want scrolling / scale view? Which charts do they want hidden by default? etc. etc.

If this could be a feature request then by all means please add it. It seems that user data suffices for the scripts, the only thing needed is some UI in the accounts/group admin sections to access all user data entries.

Thanks for the feedback @david.glickman - i’ve created a feature request and captured all of this information that we have discussed. REF#84409