- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 05:28 AM
I have a simple button to add new skills. When user clicks on this button, it takes them to the following URL.
https://INSTANCE.service-now.com/esc?id=form&table=sys_user_has_skill&sys_id=-1
I want to auto populate the User with the logged in user. How to do this?
Client script in the widget:
api.controller = function($window) {
/* widget controller */
var c = this;
// Function to handle button click
c.addSkill = function() {
var hosturl = 'https://' + $window.location.host;
$window.open(hosturl + "/esc?id=form&table=sys_user_has_skill&sys_id=-1", '_blank');
};
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 05:57 AM
Hi @vidhya_mouli,
Create client script onload for the sys_user_has_skill & get logged in user there with g_user.userID. As the widget you are using is form widget it will render the client script for the form.
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul
ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 05:57 AM
Hi @vidhya_mouli,
Create client script onload for the sys_user_has_skill & get logged in user there with g_user.userID. As the widget you are using is form widget it will render the client script for the form.
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul
ServiceNow Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2024 09:23 AM
Can you please write this on server side:
data.skill = "";
data.user_id = gs.getUserID();
var grSkill = new GlideRecord("sys_user_has_skill");
grSkill.addQuery("user",data.user_id );
grSkill.query();
if(grSkill.next())
{
data.skill = grSkill.skill;
}
Client side :
api.controller = function($window) {
/* widget controller */
var c = this;
// Function to handle button click
c.addSkill = function() {
var hosturl = 'https://' + $window.location.host;
$window.open(hosturl + "/esc?id=form&table=sys_user_has_skill&sys_id=-1+'&skill='+c.data.skill+'&user='+c.data.user_id", '_blank')
};
};
Please accept the solution and mark it helpful, if it helps