function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Neha LundNeha Lund 

How to get the logged in User's profile in Javascript ? pure javasccript no class, no VF page

I am new to Javascript.

swatKatswatKat

Use '{!$Profile.Name}' within quotes wherever u need the profile name in javascript.

Neha LundNeha Lund

No..this did not work...

swatKatswatKat

Can you paste your code please. The following works.

 

  <script>
   alert('{!$Profile.Name}');  
  </script>

 

Neha LundNeha Lund

I want to fetch logged inuser's profile Id in home page component, no code as such

 

Neha LundNeha Lund

I used this in the home page component

alert('Profile: {!$Profile.Id}'); } </script>

 and it display profile {!profile.Id} as it is..

swatKatswatKat

I had pasted that code before i knew dat u r tryng it in a home page component. This works on a vf page actually.

Neha LundNeha Lund

That's why I have mentioned No page.. well do you know whether it can be achieved in Home page component ?

 

swatKatswatKat

What do u want to do on the basis of the profile Id ? I am not sure if its viable for your requirement but u cn try to assign a vf page to ur component and do all the stuff there.

Neha LundNeha Lund

I just want to fetch the profile Id and if that profileId matches what I want then just bypass else nothing

Avidev9Avidev9
Seems like a unique requirement.
I don't think you can get Profile Id without any CODE.

There is no way you can access API without the code, you will need either JS or VF page for this.
Yoganand GadekarYoganand Gadekar

If you want to see the logged in uer's profile on aclick of a button say on account just do following;

 

1. Create a formula field : $Profile.Name (api name of formula field: .profile_name__c)

2. Your java script as below:

 

            {!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}

            var accountonwerid = '{!Account.profile_name__c}';
             alert(accountonwerid);

 

Hit kudos and mark this answer if it helps you in any way.

 

Thanks

Avidev9Avidev9
Well creating a formula field and accessing the same wont work via homepage component. Home page component is just a place holder for HTML content and is different from VF pages.

The HTML area doesnt allow anytype of merge fields.
Avidev9Avidev9
Can you elaborate your requirement lil bit ?
You can do one thing, You can create a VF page and host the same from Homepage component using a HTML iframe. In this will you will get access to MergeFields as well as Controller.