Switch logo based on user

I need the ability to display a logo on the page based on which Account is logged in.

I have multiple clients using the same app. User Accounts are tied to Facilities and Facilities roll up to a Company. The logos are stored as an image on the Company record. I need to display the Company logo on each page. The logo needs to be the one for the company they belong to. I have not been able to figure out a way to do this. Has anyone successfully accomplished something similar?  I'd love some advice on how to do this.

Thanks.

 

1 Like

I would utilize this feature as well. Any update?

This code snippet should be able to do it:

$(document).on("knack-scene-render.any", function(event, scene) {
    $("#kn-app-header").find("img").attr("src", logolink);
});

You’ll have to use API calls to get the image file’s url and substitute it with logolink.

1 Like

Thanks for the suggestion Arjun.

I created a work around where I put a field for images in the object that contains the company info so that I didn’t have to mess with API calls. I put a Details block at the top of each page that has only that field in it. It’s a bit kludgy but it works!

1 Like

Create a company logo field in the Account object, then you can get the field anywhere by using this:
Knack.getUserAttributes().values.field_123

To apply this to @Arjun’s example:

$(document).on("knack-scene-render.any", function(event, scene) {
  const loggedIn = Knack.getUserAttributes()
  if (loggedIn) {
    const logoLink = Knack.getUserAttributes().values.field_123
    $("#kn-app-header").find("img").attr("src", logoLink)
  }
})

To get the logo field inside the Account in the first place, you could do one of these:

  • Anytime you update the company’s logo—I assume your app has a Form that does this—on that form, create a Record Rule that updates the connected Account.

  • Or you might use a Text Formula. Text Formulas have the ability to access a Connected object’s fields. Because Companies are connected to Facilities and Facilities are connected to Accounts, you can access the Company fields through the Account, it’s just a matter of playing around with Connections until the Text Formula in the Account lets you access the Company Logo.

1 Like