Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Removing an Option-Set value from the Option-Set onSave event, appears to clear the data contained.

Posted on by 990

Hello All,

Option set value is getting clear if we remove the specific option from it.

example: In Case form we have status reason field, on save of a case we are changing the status reason for the record. If the record's status reason say "Submitted" then we want to remove "Assigned" status reason from option set which we are doing via jscript but, it's clearing the current value of option set too.

var control = Xrm.Page.getControl("statuscode");
var status = Xrm.Page.data.entity.attributes.get("statuscode");
if (status.getValue() == '950000017') {
       control.removeOption(950000021);
      Xrm.Page.getControl("statuscode").setDisabled(true);
}
else {
     control.removeOption(950000017);
     Xrm.Page.getControl("statuscode").setDisabled(false);
}

*This post is locked for comments

  • Suggested answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: Removing an Option-Set value from the Option-Set onSave event, appears to clear the data contained.

    Hi Rahul,

    In If Condition you are checking the current Value and removing other Option set Value.

    But In Else Condition you removed current value. I think it is going to else loop because you gave condition like

    if (status.getValue() == '950000017') {}

    Try after remove ''

    I mean

    if (status.getValue() == 950000017) {}

    If this is not the problem then try following code

    var control = Xrm.Page.getControl("statuscode");

       var status = Xrm.Page.getAttribute("statuscode").getOptions();

       if (Xrm.Page.getAttribute("statuscode").getValue() == 950000017) {

           obj.removeOption(950000021);

           Xrm.Page.getControl("statuscode").setDisabled(true);

       }

       else {

           obj.removeOption(950000017);

           Xrm.Page.getControl("statuscode").setDisabled(false);

       }

    Hope it will helps you

    Thanks.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Removing an Option-Set value from the Option-Set onSave event, appears to clear the data contained.

    please clarify once you save record , as per your code you remove the either option and you disable the field as well...then what is the problem using formtype.

    as you mentioned the code execute when you save the record.

  • Rahul-Waghmare Profile Picture
    Rahul-Waghmare 990 on at
    RE: Removing an Option-Set value from the Option-Set onSave event, appears to clear the data contained.

    Thanks for reply.

    Auto save is already disabled. We need this functionality to run on all form type, not only Create.

    Regards,

    Rahul

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Removing an Option-Set value from the Option-Set onSave event, appears to clear the data contained.

    ist due to auto save functionality, and problem with if else loop .

    use formtype in your code   if(Xrm.Page.ui.getFormType()==1 )

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans