I have a custom entity. Added this custom entity as a subgrid in Contact form and I enabled quick create form for custom entity. In custom entity, there are two lookup fields A and B. B has reference of A. I would like to filter B values depending upon A value. I have written javascript by using "addPreSearch" function while on load form. It is working fine.
But if A value is not there, B should not show any values, I should empty the lookup values of B. It is not working. How can I empty the values of B if A value is not there.
There are times where we have to educate end users/ client on how to do stuff. This may be one of that training you can provide to your users.
Then you can't hide that in a support way. Sorry.
Yes Ravi, User have privilege to create the record.
Unfortunately no, you can't hide that new button. One option as suggested above is to remove the create privledges if that suits your requirement (which I doubt as its a contact entity which you may want your users to create)
Hope this helps.
Hi,
if I am not mistaken, you cant hide the "New" button, but you can disable it by remove the create privilege from related security role.
Hi Ravi,
This logic is working fine. Thanks for your suggestion. If A is empty, B lookup values are empty. But it showed to create new in lookup. I made it as read only of all the field to restrict new creation. Whether can we hide "New" option in lookup value selector.
Hi,
if you are refering to clearing the lookup B filter, refer to the suggestion from Ravi
Hi Wei Jie,
Thanks for your suggestion. I can able to set the field as null. But I would like to set the lookup values are empty.
If you want to restrict on the front end i.e within the form then you need to add some dummy filter which doesn't return any results. Below is a sample script which filters contacts by account
=========
function filterContactsByAccount() {
if (Xrm.Page.getControl("new_contact") !== null) {
Xrm.Page.getControl("new_contact").addPreSearch(addFilter);
}
}
function addFilter() {
var AccountId = Xrm.Page.data.entity.attributes.get("new_account").getValue();
if (AccountId !== null) {
AccountId = AccountId[0].id.replace("{", "").replace("}", "");
var filter = "<filter type='and'>" +
"<condition attribute='parentcustomerid' operator='eq' value='" + AccountId + "'/>" +
"</filter>";
Xrm.Page.getControl("new_contact").addCustomFilter(filter);
}
else {
var filterDummy = "<filter type='and'>" +
"<condition attribute='contactid' operator='null' />" +
"</filter>";
Xrm.Page.getControl("new_contact").addCustomFilter(filterDummy);
}
}
===============
Hope this helps.
Hi,
If you want to do it on a save then you can simply do it with a workflow and use clear to clear the values.