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 check if a field is blank and if so do something...

(0) ShareShare
ReportReport
Posted on by 26

On my entity I have a dozen or so fields.  When the field called, "ExtractID" is blank, the users are suppose to fill in the data for the other fields.  When Extract ID contains data, I then need all other fields to wipe out the data (so to be null).

How can I do this with java script?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    Hi,  

     could be something along these lines:

    if(Xrm.Page.getAttribute("...").getValue() != null)//Check if extractid field is not null, then wipe out all other fields

    {

       Xrm.Page.getAttribute("...").setValue(null);

       Xrm.Page.getAttribute("...").setValue(null);

       Xrm.Page.getAttribute("...").setValue(null);

       Xrm.Page.getAttribute("...").setValue(null);

     ...

    }

    else{ //Otherwise, make those other fields required

       Xrm.Page.getAttribute("...").setRequiredLevel("required");

       Xrm.Page.getAttribute("...").setRequiredLevel("required");

       Xrm.Page.getAttribute("...").setRequiredLevel("required");

       Xrm.Page.getAttribute("...").setRequiredLevel("required");

     ...

    }

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    You can use following code to get value of a field:

    var fieldvalue = Xrm.Page.getAttribute("schema field name here").getValue();

    To set field to required level (when your ExtractID is empty) you can use following:

    Xrm.Page.getAttribute("other field schema name").setRequiredLevel("required");

    To empty the same field when ExtractID is not empty you can use

    Xrm.Page.getAttribute("other field schema name").setRequiredLevel("none");

    Xrm.Page.getAttribute("other field schema name").setValue(null);

    Feel free to get in touch if you have trouble combining this lines.

  • USA80 Profile Picture
    26 on at

    I can't make those fields required as sometimes the people filling out the form wont know what the answer is for those fields yet.  By default these other fields are filled in first, and then the record is usually saved.  Then the ExtractID field is filled in later.  When this field is filled in, I need those other fields to be null.  But if those other fields have data in them and ExtractID field is blank I need the data to show in those fields.  Hope that makes sense.

  • ashlega Profile Picture
    34,477 on at

    If you don't want them to be required, don't make them required - just remove that "else".. If you want to hide the fields at some point, use setVisible:

    msdn.microsoft.com/.../gg334266.aspx

  • USA80 Profile Picture
    26 on at

    I can't make the fields required, is there another way?

  • USA80 Profile Picture
    26 on at

    oh, I didn't realize I could just have an If without a else if.

  • USA80 Profile Picture
    26 on at

    I have the below and getting an error on get.Value

    function iBAMExtractIDOnChange()

    {

    var iBAMExtractID = Xrm.Page.getAttribute("nhs_ibamextractidlookup").getValue();

    if (iBAMExtractID != null || iBAMExtractID != 'undefined' || iBAMExtractID !='')

    {

    Xrm.Page.getControl("new_claimformat").setValue(null);

    Xrm.Page.getControl("nhs_claimsextractlayoutcomments").setValue(null);

    Xrm.Page.getControl("nhs_fileformat").setValue(null);

    Xrm.Page.getControl("new_invoiced").setValue(null);

    Xrm.Page.getControl("new_frequency").setValue(null);

    Xrm.Page.getControl("nhs_filetype").setValue(null);

    Xrm.Page.getControl("new_trailerfile").setValue(null);

    Xrm.Page.getControl("nhs_claimsextractftpprovider").setValue(null);

    Xrm.Page.getControl("new_finalftpfolder").setValue(null);

    Xrm.Page.getControl("new_filename").setValue(null);

    }

    }

  • USA80 Profile Picture
    26 on at

    guessing it because it is lookup field, but I don't care what is in this field.  just that it contains data

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try that:

    function iBAMExtractIDOnChange()

    {

    var iBAMExtractID = Xrm.Page.getAttribute("nhs_ibamextractidlookup").getValue();

    if (iBAMExtractID != null || iBAMExtractID != 'undefined' || iBAMExtractID !='')

    {

    Xrm.Page.getAttribute("new_claimformat").setValue(null);

    Xrm.Page.getAttribute("nhs_claimsextractlayoutcomments").setValue(null);

    Xrm.Page.getAttribute("nhs_fileformat").setValue(null);

    Xrm.Page.getAttribute("new_invoiced").setValue(null);

    Xrm.Page.getAttribute("new_frequency").setValue(null);

    Xrm.Page.getAttribute("nhs_filetype").setValue(null);

    Xrm.Page.getAttribute("new_trailerfile").setValue(null);

    Xrm.Page.getAttribute("nhs_claimsextractftpprovider").setValue(null);

    Xrm.Page.getAttribute("new_finalftpfolder").setValue(null);

    Xrm.Page.getAttribute("new_filename").setValue(null);

    }

    }

  • ashlega Profile Picture
    34,477 on at

    What error are you getting? (It does not matter if it's a lookup or not)

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