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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Set value of two option field that's in focus w javascript

(0) ShareShare
ReportReport
Posted on by 17

Hey everyone,

GOAL:

I have a function thats triggered on the change of a two option set.

If the user sets the value to false, they receive a prompt asking them for the reason behind this. If the user cancels or enters nothing. the field is set back to true.

ISSUE:

the value of gg_markfordeactivation will only ever be set back to true if the mouse hovers over the field. 

this also cause issues with the prompt entering a random never ending loop sometime. please help me here.

here is the code, line 25 is where the issue starts

function contactCancelationReason(executionContext) {
    'use strict';
    var formContext = executionContext.getFormContext(),
        mfdLogicalName = "gg_markfordeactivation",
        mfdField = formContext.getAttribute(mfdLogicalName),
        mfdValue = mfdField.getValue();

    // check to see if the field exists
    if (mfdField !== null) {

        // checks if mfd was set to false
        if (mfdValue === 0) {

            // pop to ask for reason 
            var reason;
            reason = prompt("Please decribe the reason why this record is not to be deleted...");
        
            // checks if a reason was enterd
            if (reason !== "null" || reason !== null || reason !== "") {
                
                // yes, send http request to create a note
            
            } else {
                // no, set mfd back to true
                Xrm.Page.getAttribute(mfdLogicalName).setValue(true);
                return;
            }
        }
    }
}

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Hi, 

    What format are you using for your Yes/No field ?  Can you please try with the check-box format and give a feedback ? 

    Thank you 

  • Angus Wright Profile Picture
    17 on at

    Thanks for the response Mehdi.

    I was using a yes/no option field. I tried changing to a toggle box and the same result.

    I even simplified the code to if the value is set to no. change to yes, not even this will change the value.

    attached for reference

    function contactCancelationReason(executionContext) {
        'use strict';
        var formContext = executionContext.getFormContext(),
            mfdLogicalName = "gg_markfordeactivation",
            mfdField = formContext.getAttribute(mfdLogicalName),
            mfdValue = mfdField.getValue();
    
        // check to see if the field exists
        if (mfdField !== null) {
    
            // checks if mfd was set to false
            if (mfdValue == 0) {
    
                // set value back to true 
                Xrm.Page.getAttribute("gg_markfordeactivation").setValue(true);
                return;
            }
        }
    }

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans