<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Determine current user in a Client Script? in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237805#M889789</link>
    <description>&lt;P&gt;I have need to confirm an operation with the current user, and need to know the current user's ID. &lt;BR /&gt;&lt;BR /&gt;I am familiar with gs.getUserID(), but that appears to be a server-side function, usable only in a business rule. &lt;BR /&gt;&lt;BR /&gt;I also would like to use the confirm() function, which appears a client-side function, usable only in a client script. &lt;BR /&gt;&lt;BR /&gt;So, is any one aware of something similar to gs.getUserID() that will work in a client script? Or something similar to confirm() that will work in a business rule? &lt;BR /&gt;&lt;BR /&gt;Thanks, &lt;BR /&gt;Dave&lt;/P&gt;</description>
    <pubDate>Wed, 28 Oct 2009 19:02:32 GMT</pubDate>
    <dc:creator>dstuart</dc:creator>
    <dc:date>2009-10-28T19:02:32Z</dc:date>
    <item>
      <title>Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237805#M889789</link>
      <description>&lt;P&gt;I have need to confirm an operation with the current user, and need to know the current user's ID. &lt;BR /&gt;&lt;BR /&gt;I am familiar with gs.getUserID(), but that appears to be a server-side function, usable only in a business rule. &lt;BR /&gt;&lt;BR /&gt;I also would like to use the confirm() function, which appears a client-side function, usable only in a client script. &lt;BR /&gt;&lt;BR /&gt;So, is any one aware of something similar to gs.getUserID() that will work in a client script? Or something similar to confirm() that will work in a business rule? &lt;BR /&gt;&lt;BR /&gt;Thanks, &lt;BR /&gt;Dave&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2009 19:02:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237805#M889789</guid>
      <dc:creator>dstuart</dc:creator>
      <dc:date>2009-10-28T19:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237806#M889790</link>
      <description>&lt;P&gt;Hopefully this will be useful:&lt;BR /&gt;http://wiki.service-now.com/index.php?title=The_g_user_Object&lt;BR /&gt;&lt;BR /&gt;I cannot think of a server analog for confirm(). Since the work is being done on the server, it doesn't offer the opportunity to prompt the user for confirmation. If at all possible, that should be done on the client. But if you describe what you're trying to do, maybe someone will have an idea.&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Oct 2009 19:16:34 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237806#M889790</guid>
      <dc:creator>CapaJ</dc:creator>
      <dc:date>2009-10-28T19:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237807#M889791</link>
      <description>&lt;P&gt;Situation: A user is trying to update a form. I need to verify that the form being updated does, in fact, belong to the current user. If it does, fine. &lt;BR /&gt;&lt;BR /&gt;If the form does not belong to the current user, I check to see if the current user has the appropriate role(s) to allow the update, and then I want to confirm with the current user that the do want to proceed. &lt;BR /&gt;&lt;BR /&gt;The confirm() function will let me do the confirmation in the client script. However, I can't get the current user's ID. &lt;BR /&gt;&lt;BR /&gt;I'll take another look at the g_user object and functions. &lt;BR /&gt;&lt;BR /&gt;Thanks, &lt;BR /&gt;Dave &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Oct 2009 19:29:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237807#M889791</guid>
      <dc:creator>dstuart</dc:creator>
      <dc:date>2009-10-28T19:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237808#M889792</link>
      <description>&lt;P&gt;Thanks for the pointers. &lt;BR /&gt;&lt;BR /&gt;The g_user.userID; call gave me what I needed. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Dave&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Oct 2009 21:11:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237808#M889792</guid>
      <dc:creator>dstuart</dc:creator>
      <dc:date>2009-10-29T21:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237809#M889793</link>
      <description>&lt;P&gt;I know this post is little old, but is the closest I get to what I'm trying to find.&lt;BR /&gt;&lt;BR /&gt;We have a form that HR uses to terminate employees.&lt;BR /&gt;&lt;BR /&gt;On this form, we have the field: Affected User (u_requested_by).&lt;BR /&gt;&lt;BR /&gt;We need some sort of prevention from HR to terminate themselves... Yes. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Could not find a way yet to get match the current user logged in the portal to the user being selected in that field.&lt;BR /&gt;Also, should clear the field and show a message on top.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 03:28:51 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237809#M889793</guid>
      <dc:creator>Luiz Lucena</dc:creator>
      <dc:date>2019-02-02T03:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237810#M889794</link>
      <description>&lt;P&gt;Assuming&amp;nbsp;u_requested_by is a reference field to the user table, reference qualifier&amp;nbsp;can be used to getting self-selected.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 05:40:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237810#M889794</guid>
      <dc:creator>puneetgoels1</dc:creator>
      <dc:date>2019-02-02T05:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237811#M889795</link>
      <description>&lt;P&gt;I'd suggest Opening a new post so you can put this question together with the specifics about your question.&lt;/P&gt;
&lt;P&gt;This allows you to mark it as answered and will probably get more views as it'll be "new".&lt;/P&gt;
&lt;P&gt;You could use a reference qualifier on the variable to exclude the logged in user.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2019 05:46:44 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237811#M889795</guid>
      <dc:creator>Jace Benson</dc:creator>
      <dc:date>2019-02-02T05:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237812#M889796</link>
      <description>&lt;P&gt;I could get something on the current Reference Qualifier we had:&lt;BR /&gt;&lt;BR /&gt;Added this filter:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;var filter = 'active=true^sys_id!=javascript:gs.getUserID()^';&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 17:42:00 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237812#M889796</guid>
      <dc:creator>Luiz Lucena</dc:creator>
      <dc:date>2019-02-04T17:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237813#M889797</link>
      <description>&lt;P&gt;yeah. Is it working?&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 19:37:46 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237813#M889797</guid>
      <dc:creator>puneetgoels1</dc:creator>
      <dc:date>2019-02-04T19:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237814#M889798</link>
      <description>&lt;P&gt;Yep, like a charm!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Feb 2019 21:16:14 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2237814#M889798</guid>
      <dc:creator>Luiz Lucena</dc:creator>
      <dc:date>2019-02-05T21:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2788852#M1071416</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Yes, you can get the current user's ID in a client script using g_user.userID. This is equivalent to gs.getUserID() in server-side scripting. For the confirm() function, you can use gs.addInfoMessage() or gs.addErrorMessage() in a business rule to display a confirmation or error message to the user. However, these functions do not stop the execution of the script or wait for user input like the confirm() function does in client-side scripting. Here is a summary: - To get the current user's ID in a client script, use g_user.userID. - To display a message to the user in a business rule, use gs.addInfoMessage() or gs.addErrorMessage(). - Note that gs.addInfoMessage() and gs.addErrorMessage() do not stop the execution of the script or wait for user input like the confirm() function does in client-side scripting. &lt;/SPAN&gt;&lt;A href="https://nowkb.com/" target="_blank" rel="noopener"&gt;nowKB.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2024 09:25:57 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2788852#M1071416</guid>
      <dc:creator>Swarup Patra</dc:creator>
      <dc:date>2024-01-11T09:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2793324#M1072896</link>
      <description>&lt;P&gt;Yes, you can achieve this by using the following methods:&lt;/P&gt;&lt;P&gt;1. To get the current user's ID in a client script, you can use the GlideUser (g_user) object. Here is a sample code:&lt;/P&gt;&lt;P&gt;javascript&lt;BR /&gt;var userID = g_user.userID;&lt;BR /&gt;alert("User ID is: " + userID);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2. To use a confirmation dialog in a business rule, you can't directly use the confirm() function as it's a client-side function. However, you can set a flag in the business rule and then check this flag in a UI action or client script to show the confirmation dialog. Here is a sample code:&lt;/P&gt;&lt;P&gt;In Business Rule:&lt;/P&gt;&lt;P&gt;javascript&lt;BR /&gt;current.u_confirm_flag = true;&lt;BR /&gt;current.update();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;In Client Script:&lt;/P&gt;&lt;P&gt;javascript&lt;BR /&gt;if(current.u_confirm_flag == true){&lt;BR /&gt;var answer = confirm("Are you sure you want to proceed?");&lt;BR /&gt;if (answer){&lt;BR /&gt;// proceed with the operation&lt;BR /&gt;}&lt;BR /&gt;else{&lt;BR /&gt;// cancel the operation&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Please note that you need to replace 'u_confirm_flag' with your actual field name.&lt;/P&gt;&lt;P&gt;To summarize:&lt;/P&gt;&lt;P&gt;- Use g_user.userID to get the current user's ID in a client script.&lt;BR /&gt;- Set a flag in the business rule and check this flag in a client script to show a confirmation dialog.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;nowKB.com&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 09:14:54 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2793324#M1072896</guid>
      <dc:creator>Ramesh Lohar</dc:creator>
      <dc:date>2024-01-16T09:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2793496#M1072971</link>
      <description>&lt;P&gt;&lt;BR /&gt;Sure, Dave. Here's how you can achieve this:&lt;/P&gt;&lt;P&gt;1. To get the current user's ID in a client script, you can use the GlideUser (g_user) object. Here's a sample code:&lt;/P&gt;&lt;P&gt;javascript&lt;BR /&gt;var userID = g_user.userID;&lt;BR /&gt;alert("User ID is: " + userID);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;2. To use a confirmation dialog in a business rule, you can't directly use the confirm() function as it's a client-side function. However, you can achieve similar functionality by setting up a UI Action with a client-side script that calls the confirm() function and then calls the server-side script based on the user's response. Here's a sample code:&lt;/P&gt;&lt;P&gt;javascript&lt;BR /&gt;// Client-side script&lt;BR /&gt;if (confirm('Are you sure you want to proceed?')) {&lt;BR /&gt;// If user clicked 'OK', call the server-side script&lt;BR /&gt;gsftSubmit(null, g_form.getFormElement(), 'proceed');&lt;BR /&gt;} else {&lt;BR /&gt;// If user clicked 'Cancel', do nothing&lt;BR /&gt;return false;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Server-side script&lt;BR /&gt;if (typeof window == 'undefined') {&lt;BR /&gt;proceed();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;function proceed() {&lt;BR /&gt;// Your business rule code here&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Remember to check the 'Client' checkbox for this UI Action to make it run on the client-side.&lt;/P&gt;&lt;P&gt;To summarize:&lt;/P&gt;&lt;P&gt;- Use g_user.userID to get the current user's ID in a client script.&lt;BR /&gt;- Use a UI Action with a client-side script to create a confirmation dialog in a business rule. The client-side script should call the confirm() function and then call the server-side script based on the user's response.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;nowKB.com&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jan 2024 10:40:21 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2793496#M1072971</guid>
      <dc:creator>Rajdeep Ganguly</dc:creator>
      <dc:date>2024-01-16T10:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: Determine current user in a Client Script?</title>
      <link>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2796364#M1073913</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Sure, you can determine the current user in a Client Script in ServiceNow by using the 'g_user' object. Here is a sample code: javascript var user = g_user.userName; alert('Current user is: ' + user); In this code: - 'g_user' is a global object that is available in client-side scripting. - 'userName' is a property of the 'g_user' object that holds the user ID of the current user. So, to summarize: - Use the 'g_user' object in client-side scripting to determine the current user. - Access the 'userName' property of the 'g_user' object to get the user ID of the current user. - You can display the user ID in an alert box or use it in your script as needed. &lt;/SPAN&gt;&lt;A href="https://nowkb.com/" target="_blank" rel="noopener"&gt;nowKB.com&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 09:25:39 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/determine-current-user-in-a-client-script/m-p/2796364#M1073913</guid>
      <dc:creator>Swarup Patra</dc:creator>
      <dc:date>2024-01-18T09:25:39Z</dc:date>
    </item>
  </channel>
</rss>

