I installed CRMFetchKit, which makes it very simple to execute FetchXML queries and act on the results. It’s easy to use the CRM “Advanced Find” feature to build the list of data you need and export the XML. From here, you just need to paste it into code and insert your variables.
After the results are returned, the id field is extracted using the same field name that is used in the attribute elements of the XML query. In this case, the name and id are used to populate a lookup, which gets populated differently than a standard CRM text field. Brackets are required for setting the id fields of lookups. The relevant code is below:
This was used to link to the record when the name of the selected lookup value is clicked, as is the behavior of a standard CRM lookup.
For calling the actual lookup dialogue, I created a function to encapsulate the method call so that I could get intellisense when determining what fields I would fill in when I calling it.
Here is the code I used to call the lookup using the above function. The State lookup should be filtered to show only the states that belong to the selected Country. If it’s just a standard lookup, only the lookupStyle and lookupTypes parameters are required.
For another requirement, the client wanted “cloning” functionality for an entity, to be called from a ribbon button click. When the ribbon button is clicked, a new window should open for creating a new entity and the relevant fields should be populated. Installing the CRM Visaul Ribbon Editor makes it a snap to add ribbon buttons. I don’t know any other way to do it, but this seems to be very easy. So there are basically three steps to the process.
1. Collecting the field values from the source record. The fields need to be treated differently depending on the field type, as usual
2. Define the values that will be populated into the destination record
3. Open the new form, passing the values to be populated (AGREEMENT is the entity type name (in our case, ‘iis_agreement’)