Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript

(0) ShareShare
ReportReport
Posted on by 1,942

Hi all,

I have developed a code to compare the logged in user name and the owner of the record username (i.e. onwerid). For some reason it is not comparing the two values.

function finalq(){
debugger;
var luser = Xrm.Page.context.getUserName();
var accmg = Xrm.Page.getAttribute("ownerid").getValue();
var accmgtext = accmg[0].name;
accmgtext = accmgtext.toString();
alert(accmgtext);
if(luser == "accmgtext"){
Xrm.Page.getControl("new_finalcustomerquote").setDisabled(true);
}
else{
Xrm.Page.getControl("new_finalcustomerquote").setDisabled(false);
}
}

*This post is locked for comments

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: Javascript

    I appreciate all of you for helping me out. Thank you

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Javascript

    Your code is correct except for this line:

    if(luser == "accmgtext")

    it should be

    if(luser == accmgtext)

  • Suggested answer
    ganeshm Profile Picture
    ganeshm on at
    RE: Javascript

    your code is right ,but please remove the "accmgtext" and change to accmgtext its a variable

    if(luser == "accmgtext")<--

  • Suggested answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,401 on at
    RE: Javascript

    if(luser == "accmgtext"){

    modify it to

    if(luser == accmgtext){

  • Verified answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Javascript

    Hi Vighnesh,

       I think you just need to remove quotes around accmgtest in the if condition:

    if(luser == accmgtext)

  • Suggested answer
    Sayhaitokumar Profile Picture
    Sayhaitokumar 7,042 on at
    RE: Javascript

    Hello Vighnesh,

    Try this code

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

    var ownerID = owner[0].id;

    var ownerName = owner[0].name;

    var LoggedInUser = Xrm.Page.context.getUserId();

    After getting the OwnerId and LoggedIn userId, compare the value.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans