How to add the current user to a people picker using javascript coding in document library

Hi Everyone,
This is my scenario,
I have a document library,for this if any user uploads a document,there we have three content types(Ex:content1,content2,content3)
if the uploaded user is from content 1(here we have four columns name,assigned to ,status,published to) after uploading the document the document has to be updated.so when the document is updated by the user then automatically the published filed people
picker has to be filled up with the current user name this is done by using java script object model programming.
i am stuck with this can anyone help me..............
thanks in advance
Ramu

Hi,
I understand that you want to set a people picker field value automatically to current user. You can use these ECMA scripts on your EditForm.aspx page. Edit the page in SharePoint designer and add the code before a </asp:Content> tag.
 <script type="text/javascript">
var context = null;
 var web = null;
 var currentUser = null;
ExecuteOrDelayUntilScriptLoaded(GetUserLoginName, "sp.js");
function GetUserLoginName() {
context = new SP.ClientContext.get_current();
 web = context.get_web();
 this._currentUser = web.get_currentUser();
 context.load(this._currentUser);
 context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
 function onSuccessMethod(sender, args) {
 var today = new Date();
 alert('Name:' + this._currentUser.get_title() + '\n Login:' + this._currentUser.get_loginName()); document.getElementById('ctl00_m_g_9b4b3950_80d8_4e6e_b2fa_241b727d83d4_ctl00_ctl02_ctl00_ctl02_ctl00_ctl00_ctl04_ctl00_ctl00_ctl04_ctl00_ctl00_UserField_upLevelDiv').innerHTML=this._currentUser.get_title();//you
need to change the ID here to you people picker field ID. You can get the id for this field with the help of IE developer tool.
 function onFaiureMethod(sender, args) {
 alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
 </script>
For more information, please refer to this site:
Get current user’s LoginName Ecmascript Sharepoint 2010:
http://www.learningsharepoint.com/2011/05/18/get-current-users-loginname-ecmascript-sharepoint-2010/
Thanks,
Entan Ming
Entan Ming
TechNet Community Support

Similar Messages

  • How to get the Current User on the UI page?

    All,
    Could you please let me know how to get the Current user on the UI input page , i need to display the current user ID when some one clicks the submit button, i want o get the current user to display in the javascript alert box.
    Edited by: 951930 on Oct 24, 2012 12:21 PM

    lucky,
    my schema has already defined for
    <user mapField="USER_ID" default="%CurrentUser"/>
    and in my UI page
    <td oraLabel="user"></td><td oraField="user" id="userId" ></td>
    and my javascript
    function showUserId () {                        
    var curUser = document.getElementById('userId').value;
    alert(curUser);
    and i have called this function on my submit button, but i am not able to get Current Logged User ID value to show in the alert nor able to show the current logged user on the UI page.
    my requirement is on custom UI page i need to show Current Logged User in one corner of the page and also need to show the same user in alert when he submits the button.
    Appreciate for the help.
    Edited by: 951930 on Oct 25, 2012 8:42 AM
    Edited by: 951930 on Oct 25, 2012 9:06 AM

  • How to get the current user logon to portal?

    Hi Gurus,
    How to get the current user who logged into portal.
    I have a webdynpro requirement where in which I have to get the current user id who loggedinto portal which will be the input parameter of the BAPI(adaptive RFC model) which will return me employee number of the particular user.
    Can anyone send me the code to retrive the user id through webdynpro application..........
    Pts will be rewarded for useful inputs......
    Thanks in Advance,
    Dharani

    Hi Dharani,
    Using UMEfactory u can do that...
    1. create one input field,
    2. create one attribute called Uid
    3. assign Uid attribute to the input field
    4. type the following code in Doinit() method
                String uid = wdContext.currentContextElement().getUid();
         try {
         IUser user = UMFactory.getUserFactory().
         getUserByLogonID(uid);
         String userName = user.getDisplayName();
         } catch (UMException ex) {
          e.toString(); 
    5. after that go to Portal create one iview assign to particular user. then u get into the user details...
    thats it
    Regards,
    P.Manivannan

  • How to get the current user name of the host who is occupying a specific VM?

    I'm developing a winform app with c# code to manage Hyper-V. I need to remind someone if he/she would take a VM which has already been occupied by others.
    Is there any powershell cmd or WMI interface to get the current user of a specific VM?
    Thanks!

    Hiya,
    from cmd there are quser(Query user) and qwinsta(Query Session)
    which should give you that. Don't know how you can incoorperate that in C#, but that should give you something to work with :)
    https://technet.microsoft.com/en-us/library/cc785434.aspx
    https://technet.microsoft.com/en-us/library/cc788125.aspx

  • How to retrieve the current User using PL_/SQL code?

    Hi,
    How can find the current logged user within a Dynamic Page using PL/SQL code?
    Thanks.

    Hi,
    There is a function wwctx_api.get_user which returns the logged in user. You can use this in your plsql code.
    Thanks,
    Sharmila

  • How to reference the current user ID in an URL  iView

    Hi
      I have created an iview based on URL iview.
      I need to pass the logged on portal user id as parameter to a url.We are using EP6 SP2.
    Can any body help me in this regard.
    Regards
    Sayantan

    Hi SAYANTAN,
    You can create a dynpage that takes the current user id, use it to construct the url,
    and redirects to that url in doProcessBeforeOutput():
    public void doProcessBeforeOutput() throws PageException {
       Form myForm = this.getForm();
       IPortalComponentRequest request = (IPortalComponentRequest)this.getRequest();     
       IUser currUser = (IUser)request.getUser().getUser();
       String userid = currUser.getId();
       String url = "http://myUrl.com?userid="+userid;
       myForm.addRawText("<script>");
       myForm.addRawText("open(""+url+"","_self");");
       myForm.addRawText("</script>");      
    Hope that helps,
    Yoav.

  • How to find the current users logged in.

    Hi,
    I have a problem in finding the current users logged into the database and the operations they are doing.
    If u know pls help me........
    Thanks.
    K.Vijay Choudary Reddy.

    hi vijay,
    this is the OracleAS Portal Content Management forum. Please post your database related question in the Database Forum:
    General Database Discussions
    thanks,
    christian

  • How to get the current User Id

    Hi,
    is there any system variable containing the current "user code"
    because, based on current user code, i would like to get the branch from OUSR, so that, one query can display only those records pertaining to that branch.
    Thanks & Regards,
    Kr

    Hi
    You can create a formatted search to get and the following query:
    SELECT T0.U_NAME FROM OUSR T0 WHERE INTERNAL_K = $[USER]
    Paulo Calado
    SAP Business One Forums Team

  • How to find the current User Name and stored in which table

    In which table the current user name (Login) is stored?

    Hi Mohanapriya
    The query provided by Gordon can not run on query generator as the $USER is a runtime variable.
    You need to save it to a query then use it in a FMS(Formatted Search.)
    Just open a form(ex:sales order ), click the field in which you want to show the user name,
    then press ****+F2 or Tools->Search Function->Define,
    Search by Saved query,then assign the save query to the field.
    After that ,you can run the FMS(shift+F2) to get the current user info.
    Regards,
    Syn Qin
    SAP Business One Forums Team

  • How to get the current user name in Provider hosted app using appOnlyAccessToken

    Hi, 
    Please help me, how to get the HostWeb UserName in Provider Hosted App
    i have Provider hosted App, and Anonymous Authentication is enabled on AppWeb, using appOnlyAccessToken
    Below code does not return current user who Log in in hostweb, it is returning
    SharePoint App (app@sharepoint)
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;
    Below code gives a blank name when Anonymous Authentication is enabled, if Anonymous Authentication is disabled
    app prompts for credentials 
    HttpContext.Current.User.Identity.Name
    Thanks
    Ram

    Hi,
    Since you are using a provider Hosted app if you want to get the current logged in name than do not use AppOnlyAccessToken else use AccessToken which is App + user Context AccessToken.
    then 
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    clientContext.Load(web.CurrentUser);
    clientContext.ExecuteQuery();
    clientContext.Web.CurrentUser.LoginName;will return proper user Name.
    HttpContext.Current.User.Identity.Name will never return the user as this object is related to IIS server of your App Server not sharepoint.you should set this as Anonymous in case of provider hosted app.you can download the below sample which uses the AccessToken which has user name in it.https://code.msdn.microsoft.com/Working-provider-hosted-8fdf2d95
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • How to add shortcuts to user Start Menu and Taskbar using Microsoft Office 2013 OCT?

    Hello, I am kindly seeking your help.  How do I add the shortcuts for Word 2013, Excel 2013, and PowerPoint 2013 to the users Start Menu and taskbar when installing MS Office 2013 from a network installation point? I am using Office2013
    OCT to customize setup and deploying MS Office to Windows 7 x64bit clients. I tried [StartMenuFolder] and [AppData], but they did not work.

    Hi
    There is a known issue about
    changing the shortcut location for an Office 2013 application:
    When you try to change the shortcut locations for Office 2013 applications in the Office Customization Tool (OCT), you receive the following error message:
    Invalid start in folder. Please try again.
    Then, you add the Start in location for Office 2013 and run a customized installation. When you double-click the shortcuts that are displayed on the desktop, Configure shortcuts does
    not work and you receive the following error message: 
    Sorry, we couldn’t find your file. Is it possible it was moved, renamed or deleted?
    To work around this issue, type a single open bracket ([) in the Start in
    field.  
    In addition, refer to the link below on "Configure shortcuts" in OCT:
    http://technet.microsoft.com/en-us/library/cc179097.aspx#Configure_shortcuts
    Regards
    Tylor Wang
    TechNet Community Support

  • How to list the current user in sqlplus and how to switch to another?

    Assume I am in a sqlplus sesion.
    How can I display the user with whom I am currently working?
    And how can I switch (without leaving the sqlplus session) to another
    user aaa with pw=mypw?
    Peter

    By using host command
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.1.0.5.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SQL> host su oracle
    Password:
    [oracle@backup root]$ exit
    exit
    SQL>From Documentation:
    *HOST [ command ] - Execute host commands*
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14195/sqlqraa.htm#sthref1972
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com

  • How to determine the current user id!

    I have a table. And when the user insert record, I should insert the information about user who create this record in this table.
    Kostya!

    Here is an example of a trigger I use to populate a primary key and fetch the user
    created the record:
    CREATE OR REPLACE TRIGGER bi_my_table
       BEFORE INSERT
       ON my_table
       REFERENCING NEW AS NEW OLD AS OLD
       FOR EACH ROW
    DECLARE
       c1   NUMBER;
    BEGIN
       FOR c1 IN (SELECT my_table_seq.NEXTVAL next_val
                    FROM DUAL)
       LOOP
          :NEW.primkey := c1.next_val;
          :NEW.user_created := NVL (htmldb_application.g_user, USER);
       END LOOP;
    END;Denes Kubicek

  • How to get the return value of a LOV item using javascript

    Hello,
    I am trying to put an onchange attribute in the HTML Form Element Attributes field of a LOV item. The javascript should access the new return value of the item. How is this done ? All the methods I have tried give only the display value, not the return value. For example $v() returns the display value.
    Tiina

    If your item is called P1_ITEM this will give you the return value of a popup (displays description,returns key value)
    alert($x('P1_ITEM_HIDDENVALUE').value)
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How Do I Display the Current User Name on SharePoint

    I have a customer using a hosted SharePoint 2013 multi-tenant solution and they have asked to have the end user's name to be displayed when logged in. It seems like I have seen this done on other SharePoint deployments but I can't seem to figure out how
    or where to enable this now.
    Can anyone tell me how to display the current user's name in SharePoint 2013?

    Hi
    check this solution
    http://www.c-sharpcorner.com/UploadFile/sagarp/how-to-get-the-current-logged-in-user-and-display-name-using/
    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

Maybe you are looking for

  • Payment advice mailing

    hi to all, help me in this issue, how to use this bte SAMPLE_PROCESS_00002040 for sending mails to vendors how to activate this bte and change the code. thanks in advance kiran reddy Message was edited by:         kiran reddy

  • Mail app for OS X 10.5.8

    How can I get the Mail app for my late 07 Macbook? I don't have my original installation disks but would find it handy to be able to mail data without using gmail to copy and paste.

  • Explain what is Data bolt-on

    Can any one explain what is Data bolt-on?

  • System Crashs / Freezes in Games with Audigy 2 ZS b

    Hello, I can play any Game 5 min , then the Computer frezze and i must restart. I tried any pci slots, no chance My System: AMD 64 3500+ Winchester MSI K8N Diamond Kingston HyperX 024MB Geforce 6600GT I follow the Tip with the System..from ACPI Unipr

  • Microsoft Messenger Mac - Version 8.0.0

    Im using Microsoft Messenger Mac - version 8.0.0, I would like to know how to disable the built in webcam so that my friends can't see that I have a cam?? Or even use an external webcam like Logitech instead of the built in one....? Please help....?