web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get Current User data to put in Salesperson in Quote Form

(0) ShareShare
ReportReport
Posted on by

Hi, this is probably a simple answer but can't get my head quite around it

In quote product I want to be able to put the current person as the salesperson.

So far I have the following;

function retrieveDefaultSales()
{
  var check = Xrm.Page.getAttribute("salesrepid").getValue();
  if (check == null)
  {
    var salesid = Xrm.Page.context.getUserId();
    var option = "$select=DomainName&$filter=SystemUserId eq guid'" + salesid  + "'";
    SDK.REST.retrieveMultipleRecords("SystemUser", option, retrieveUser, function(error) { alert(error.message); }, function(){});
    Xrm.Page.getAttribute("salesrepid").setValue(salesid);
  }
}

function retrieveUser(retirevedUser)
{
  if(retirevedUser.length > 0)
  {
    var salesperson = retirevedUser[0].DomainName;
    alert(salesperson);
    Xrm.Page.getAttribute("salesrepid").setValue(salesperson);
  }
}


Any ideas how to get this actually working? I don't seem to have any error messages coming up it simply isn't populating the lookup field

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Royal King Profile Picture
    27,686 on at

    Use the below one line code to populate current logged in user ,

    Xrm.Page.getAttribute("salesrepid").setValue([{ id: Xrm.Page.context.getUserId(), name: Xrm.Page.context.getUserName(), entityType: "systemuser" }] );

  • Community Member Profile Picture
    on at

    Worked great, thank you!

    Was hoping there'd be a simpler way

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Harrison,

    The salesrep id is the lookup field.

    So you need to define the ID and the Name

    Example:

    Xrm.Page.getAttribute("lookupid").setValue([{ id: "guid", name: "the name", entityType: "entityname"}]);

    If your code here: if(retirevedUser.length > 0) got the retrievedUser then you can just add this:

    function retrieveUser(retirevedUser, salesId) //add the salesid

    {

      if(retirevedUser.length > 0)

     {

       //var salesperson = retirevedUser[0].DomainName;

     //change the retirevedUser[0].DomainName with full name

      var salesperson = retirevedUser[0].FullName;

       alert(salesperson);

       //Xrm.Page.getAttribute("salesrepid").setValue(salesperson); --> you should replace this line

       Xrm.Page.getAttribute("salesrepid").setValue([{ id: salesId, name: "the name", entityType: "entityname"}]);

     }

    }

    //do not forget in your query, add the full name, instead of Domain Name

    var option = "$select=FullName&$filter=SystemUserId eq guid'" + salesid  + "'";

    You can follow Chitra suggestion as well.

    Anyway here is the link of the sample code:

    crmbusiness.wordpress.com/.../crm-2011-setting-a-user-lookup-with-the-logged-in-user-with-javascript

    Just change the field name to salesrepid

    Hope this helps!

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans