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)

How to null out a field based on the change of another field?

(0) ShareShare
ReportReport
Posted on by 26

I have Field A that when this field changes, I want Field B to null out the value that is there already.  However, if this is an existing record, I don't want Field B to be nulled out when it loads, it needs to retain what is there.

How can I do this? 

*This post is locked for comments

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

    Hi USA80 ,

    1.You can add the java script event handler  on Field A .(Open form--> double click on the field A --> Navigate to Event Tab. --> Add the web resource in Form Libraries and  Add the function in Event Handlers.

    2.In the function add below code.

    if (Xrm.Page.ui.getFormType() != 2)//Not update

    {

       Xrm.Page.getAttribute("new_fieldb").setValue(""); //Set field B to null

    }

    -----------------------------------------------------

    Please mark this answer as verified if it answers your question.

    use free tool  dynamicshero.com/scheduler to schedule Workflow and Actions.

  • USA80 Profile Picture
    26 on at

    I have the below:

    function BlankProgramTypeOnChange()

    {

    if (Xrm.Page.ui.getFormType() != 2)//Not update

    {

      Xrm.Page.getAttribute("nhs_programtype").setValue(""); //Set field B to null

    }

    }

    and it is still nulling out the field on load when it shouldn't be.

  • Community Member Profile Picture
    on at

    Hi,

    When are you facing this issue? Is the form read only form? Also, where are you invoking the function(onload/onsave/onchange)?

  • USA80 Profile Picture
    26 on at

    I am facing this issue on load even though my function is set to the event of OnChange.

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

    Hi,

    Try with this  -

    function BlankProgramTypeOnChange() {
        if (Xrm.Page.ui.getFormType() === 1) {
            Xrm.Page.getAttribute("nhs_programtype").setValue(null);
        }
    }


  • USA80 Profile Picture
    26 on at

    I tried that and so on load the field isn't nulling out which is good, but now it isn't nulling out when I do change the recordtype field.

  • Suggested answer
    Community Member Profile Picture
    on at

    Then the filed itself might not being saved.Once the record is saved , are you able to see the field value after you create?(without refreshing the form) .

  • USA80 Profile Picture
    26 on at

    yes

  • Suggested answer
    Community Member Profile Picture
    on at

    Then some on load script is /business rule may be making it null. Please check  if any and disable .

  • USA80 Profile Picture
    26 on at

    They are not, as this is brand new script that I just added.  Before this the field never went null.

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