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)

Javscript On Status Change clearing field value

(0) ShareShare
ReportReport
Posted on by 274

When I toggle between the different Status (Draft, Approved, Rejected, etc) I want the value to be clear. For instance if I change the value from Draft to Approved, the workflow sets some field values. If I change to Rejected it will also set the field values, however if I toggle back to Approved I still see the value. I think I need to have javascript to clear the value onChange?

function status(fieldName) {
if (Xrm.Page.getAttribute(fieldName).getValue() == 1 ) {
Xrm.Page.getControl(arg).clearOptions()
}
else if (Xrm.Page.getAttribute(fieldName).getValue() == 2 ){
Xrm.Page.getControl(arg).clearOptions()}

}


*This post is locked for comments

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

    Hi Mitu,

    In that case just set the value to null  like Xrm.Page.getAttribute("new_xyz").setValue(null);

    replace new_xyz with your attribute name

  • Suggested answer
    Community Member Profile Picture
    on at

    also you can use OOB Business rules for clearing the fields , Please refer the belowl link :

    www.powerobjects.com/.../clearing-a-field-value-using-business-rules

  • MituCRMing Profile Picture
    274 on at

    I used the following code onChange to clear the value on field change but not setting the value back.

    function Statuschange(fieldName) {

           if (Xrm.Page.getAttribute(fieldName).getValue()) {

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

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

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

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

           }

           else {

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

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

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

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

           }

       }

  • Community Member Profile Picture
    on at

    Hi Mitu,

    first tell me what is the type of fieldName i.e. optionset twooption etc,

    and also clear your requirement

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hello,

    Your if block code is correct but else part is not correct (make sure you are writing corret field name), you need to pass value under setValue method which you want to set for example

    Xrm.Page.getAttribute("Atrributename").setValue(value that you want to set);

    Also you need to set value depending on their types, you can refer this msdn KB for your help: msdn.microsoft.com/.../gg334409.aspx

    For example it seems rejectedby is a lookup so you need to create lookup array and need to set it accordingly, you can view it in msdn KB.

    Let me know if you need more help on this.

    Thanks

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