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)

If statement not working?

(0) ShareShare
ReportReport
Posted on by 75

I'm going a bit crazy.

So I have a javascript that runs when a field changes.  This works just fine.

However, I don't want it to change every time the field changes, only when the field changes to a specific value.

So I'm using an if statement in the javascript, but it seems to ignore the if's and just does it every time anyway??

I've gone back to basics even and tried playing around with it.

function SetValue(){
var optValue = Xrm.Page.getAttribute("statuscode").getValue();
alert(optValue);
if (optValue = 10000003) {
alert("message 1");
}
if (optValue = 10000005) {
alert("message 2");
}
}

When I change the statuscode, it does all three alerts no matter what is picked??  Can someone help me figure out what I'm doing wrong?

Thanks,

Terry

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi Terry,

    You need to change your = operators to either an abstract comparison (e.g. ==) or a strict comparison (e.g., ===). You also need to check the value you are storing in the optValue variable to know how the variable will evaluate inside the if statements.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi,

    When you are writing (optValue = 10000003) which means you set option value to 10000003 and it's not comparing the options value.

    Try with this -

    function SetValue(){

    var optValue = Xrm.Page.getAttribute("statuscode").getValue();

    alert(optValue);

    if (optValue == 10000003) {

    alert("message 1");

    }

    if (optValue == 10000005) {

    alert("message 2");

    }

    }

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