Prevent to add more than one distinct record in Subgrid - Dynamics CRM 2011 RRS feed

  • Question

  • Hello Everyone,

    I am facing difficulty to implement a business logic.
    I have :

    OOB Case entity,
    Custom Entity "Issues",
    Custom Entity "Issue Name",
    Custom Entity "Issue Type"

    "Issues" Entity's form has look-up to "Issue Name" and "Issue Type" and some other fields.
    So, when user create record in Issues entity, they have to choose Issue Name and Issue type (Designed in such a way so that normal user can only choose existing Name and Type). Records for "Issue Name" and "Issue Type" entity can be created from some special security roles.

    Example of Issue Entity Record could be like this :

    Issue Entity Record 1 : Issue Name - Defaulter and Issue Type : Bribe
    Issue Entity Record 2 : Issue Name - Defaulter and Issue Type : Kickbacks
    Issue Entity Record 3 : Issue Name - Bankruptcy and Issue Type : Bankruptcy code 101
    Issue Entity Record 4 : Issue Name - Bankruptcy and Issue Type : Bankruptcy code 102

    The Case entity has a sub-grid of Issues Entity. User can create case and choose one of the existing record from Issue Entity like any Record from above example.
    Only thing user can not do is they can not add Two Issue name in the Sub-grid for one case. For example User clicks on Sub-grid and then from the Ribbon they choose Add existing record Issue, from that look up they can select one or multiple issue records but CRM should throw error if user has already added one of the record lets say

    Record 1 in Sub-grid : Issue Name - Defaulter and Issue Type : Bribe but if they try to add  Record 2 in Sub-grid : Issue Name - Defaulter and Issue Type : Kickbacks.
    Because the Issue Name is Same in this case, CRM should throw error message saying Issue Name is already added in Sub-grid and can not be added and should NOT add the record.
    In Issue entity having same Issue Name with Multiple Issue Type is not considered as Duplicate but Issue Sub-grid in Case entity with two same Issue name is considered as duplicate.

    Can somebody please help me to implement this logic how and where to write some code to implement. Please give some idea.

    Thank You for looking into my post.

    Puneet Joshi - Dynamics CRM Developer

    • Edited by Puneet Joshi Friday, November 8, 2013 4:32 AM To clarify
    Thursday, November 7, 2013 4:34 PM

All replies

  • Puneet,

    Here is one way of doing it

    1. Write Pre-Create, Pre-Update plugins on Issue entity that call a function by passing the caseid & IssueName. If there is no caseid then don't do anything just allow the user operation to go through.

    2. In the function, use the CaseId to retrieve all the related issues that match the IssueName. If you have any records returned by the retrieve then abort the create/update plugin and display the duplicate error message to the user.

    This way you can control the issue addition related to a particular case.


    If my response helps you in finding your answer then please click 'Mark as Answer' and 'Vote as Helpful'

    • Proposed as answer by Mamatha Swamy Friday, November 8, 2013 12:17 AM
    Friday, November 8, 2013 12:17 AM