简体   繁体   中英

Dynamics CRM 2016 edit lookup email from field

I am using Microsoft Dynamics 2016, and need to clean up the options in the from field of the default email form.

So the aim is to limit the results in the lookup for the email "from" field. By default it shows all companies, contacts etc. However, we will only be using queues and users in the "from" field.

How can I limit the lookup and search items to only use queues and users? It appears that this is derived from a party list, however, I can not find any information on editing a party list inputs.

I thought maybe https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_addCustomFilter would be an option, but can't work out how to feed the attribute types of queue (2020) and user (8) in to form the lookup.

Using some code from https://social.microsoft.com/Forums/en-US/3b97a306-4df7-4128-a3a9-e516c46c565d/limit-customer-lookup-in-opportunity-to-accounts-only?forum=crmdevelopment I came up with the following code:

function setFromLookupOptions()
{
    document.getElementById("from").setAttribute("lookuptypes", "8,2020");
}

However, this code just brings up errors, saying it cant setAttributes of Null (indicating it can not find the "from" field, but that's what it's labelled in the form). I have also tried using "from_i" as per the note at the top of the first block of code at https://bernado-nguyen-hoan.com/2015/10/28/correcting-available-lookup-views-when-restricting-lookup-types-via-javascript-in-crm/ however, it can't seem to find an element with that name.

So how can I do this?

There is a bit more to do with this here: https://community.dynamics.com/crm/f/117/t/186549 and the script I created to do this is:

/*
Function to only select certain entities in a lookup

To use, just edit fieldName to be the name of the field on the form you want to edit and HideEntities as an array of entities you do not want to show up.
Note that under the advanced search, you will still see these items in the drop down list, they just wont find any results.
/*

function setFromLookupOptions()
{
  var fieldName = "from";
  var HideEntities = ["customJob", "account", "contact","entitlement", "equipment", "lead"];
  Xrm.Page.getControl(fieldName).addPreSearch(function()
  {
    EmailFilter(fieldName, HideEntities);
  });
}

// Hide all of the OOB entity records from the given PartyList field.
function EmailFilter(fieldName, HideEntities)
{
  var filter;
  var i;
  for (i = 0; i<HideEntities.length; i++)
  {
    filter =
      "<filter type='and'>" +
      "<condition attribute='" + HideEntities[i] + "id' operator='null' />" +
      "</filter>";
    Xrm.Page.getControl(fieldName).addCustomFilter(filter, HideEntities[i]);
  }
}

I hope this helps someone.

Note that customJob is any other field that is showing up that you need to remove. All other instructions are at the top of the script.

for CRM2016 you can try this to show only lead and account entities in lookup popup.

var control = Xrm.Page.getControl("to");
control.getAttribute().setLookupTypes(["lead", "account"]);

Somewhat related for someone else who may find this thread & wants something a bit simpler:

I wanted to set the lookup to only contacts and users for the party list/attendees in an Appointment. This code works:

var lookupAttendees = Xrm.Page.getAttribute('requiredattendees').getLookupDataAttribute(); lookupAttendees.setLookupTypes(['contact', 'systemuser']);

Notes: The party list cannot contain records that have been not included (eg anything but contact and systemuser). So be sure to clear the party list of Accounts/Leads/etc. before running this code, otherwise it won't do anything.

Assuming that this could potentially work for any type of party list, even in email entity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM