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
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.
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.
Thanks for reply.
Auto save is already disabled. We need this functionality to run on all form type, not only Create.
Regards,
Rahul
ist due to auto save functionality, and problem with if else loop .
use formtype in your code if(Xrm.Page.ui.getFormType()==1 )
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156