How can I dynamically set a link URL based on currently logged in user?

fdsafdsafds
Kilo Contributor

I have a menu item directing to a page which contains a form. This form should display the record of the currently logged in user's company profile. What is the best way to achieve this? Below is a screenshot of the menu item, with a hardcoded sys_id (the part that I would like to set dynamically) highlighted. Thanks in advance.

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

I just wanted to check-in on this and see if this has been resolved.

If my reply above helped guide you correctly, please mark as Helpful & Correct.

Thank you!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hi,

Can you try using:

sys_id=javascript:gs.getUserID()

 

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

I was looking for the company ID, and I was able to get nearly what I needed by changing the URL to 

?id=csm_profile_company&table=core_company&sys_id=javascript:gs.getUser().getCompanyID()&view=sp;

However, I'm trying to get to the u_client_profile table, which is actually a reference on core_company. Is there a way to do this in HREF?

Hi,

Yeah, sorry, in your original post, from just glancing at it, it looked like a specific profile that was being driven by the user so I assumed it was their own sys_id. Otherwise, yea, the help is showing an example of what you could do, so I'm glad to see you took that and went a step further 🙂

So you'd want to set the table in the URL to the table with the data you want to see, so back to u_client_profile. Then it sounds like you need to sort of dot-walk within that user's company to find the right sys_id of the client profile, right?

If so, knowing you can use "javascript:" in the url, you should be able to create a script include that uses that specific users sys_id to find their company and then their client profile sys_id and return that back (which is all done in the script include to reach out to the server, find that info, and bring it back). It would be called within the URL like:

javascript:new <scriptIncludeName>().<methodName>()

Documentation on Script Include: https://docs.servicenow.com/bundle/paris-application-development/page/script/server-scripting/concep...

An example use case here: https://community.servicenow.com/community?id=community_question&sys_id=335ecfeddb9cdbc01dcaf3231f96...

I haven't personally tried this and I'm unsure if this will work or not, but it's worth a try. Normally, for the SP menu items, it's used within the condition section to show or hide a menu item, but I'm assuming the same concept could be used within the URL knowing javascript: can be used.

Please mark reply as Helpful/Correct, if applicable. Thanks!

 

 

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I just wanted to check-in on this and see if this has been resolved.

If my reply above helped guide you correctly, please mark as Helpful & Correct.

Thank you!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!