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)

JS Code to set account owner name in Sales person 1 field in quote: Is it right

(0) ShareShare
ReportReport
Posted on by

Hi All

I just wrote a javascript code to set the field of sales person1 in quote as the owner of the account.

Please can anyone check and let me know what i am doing wrong. as its giving me undefined in Salesperson1 field.

Thanks

 function SetSalesPerson1(resultXml, userid) {

      var owner= Xrm.Page.getAttribute("ownerid").getValue();
var ownerID = owner[0].id;
var ownerName = owner[0].name;
var entityType = owner[0].account;

       var lookupData = new Array();

        //Create an Object add to the array.    
        var lookupItem = new Object();


        //Set the id, typename, and name properties to the object.    
        lookupItem.id = owner.ownerID ;
       lookupItem.entityType ='account';
        lookupItem.name = owner.ownerName ;

        // Add the object to the array.      
      lookupData[0] = lookupItem;

        // Set the value of the lookup field to the value of the array.          
        Xrm.Page.getAttribute("salesperson1id").setValue(lookupData);

    }

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    use developer tools F12 to get the line causing the issue. I would imagine it is because you haven't prefixed the fieldname for salesperson1id?

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Agni,

    Please replace your function with the below one and try :

    function SetSalesPerson1(resultXml, userid) {

    var owner= Xrm.Page.getAttribute("ownerid").getValue();

       var lookupData = new Array();

       var lookupItem = new Object();

       //Set the GUID

       lookupItem.id = owner.id;

       //Set the name

       lookupItem.name = owner.name;

       lookupItem.entityType = owner.entityType;

       lookupData[0] = lookupItem;

        // Set the value of the lookup field to the value of the array.          

       Xrm.Page.getAttribute("salesperson1id").setValue(lookupData);

    }

    Hope this helps!

    I'd appreciate if you mark this as a Verified answer.

    Thanks,

    Mohit

  • Community Member Profile Picture
    on at

    Hi Mohit

    It's still giving me 'undefined'.

    Thanks

  • Suggested answer
    Community Member Profile Picture
    on at

    Is salesperson1id actually the fieldname its not "new_salesperson1id"?

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Agni,

    What is this "salesperson1id" ? is this is a lookup , please check the attribute name and attribute type it should be of lookup of systemuser entity.

    Thanks,

    Mohit

  • Community Member Profile Picture
    on at

    Hi Andy

    yes it's a field name and its salesperson1id.

    Thanks

  • Community Member Profile Picture
    on at

    Hi Mohit

    It's a field name.

    Thanks

  • Community Member Profile Picture
    on at

    Hi Mohit

    Just checked it sorry it's a lookup.

    Is this right. sorry I am still new to CRM.

    Thanks

  • Community Member Profile Picture
    on at

    Hi Andy

    Just checked it sorry it's a lookup.

    Is this right. sorry I am still new to CRM.

    Thanks

  • Community Member Profile Picture
    on at

    Hi Agni,

    I too agree with andy you are missing prefix in the attribute name "salesperson1id" it should be new_salesperson1id or xyz_salesperson1id.

    Please double check the field name.

    Thanks,

    Mohit

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