locked
Can we create 1 to 1 custom entity RRS feed

  • Question

  • Hi,

    I created one custom entity namely Account technoloty details associated with account entity. Now I can select this entity from account and enter details.  But I can enter more than one record for particular account.  Actually I need to enter one record per account or one custom entity record per account. How to restrict entering multiple records on each account.

    Please find attached screen-shots for clarifications. Please find a solution for this.


    pnoushu@hotmail.com

    Monday, December 9, 2013 7:23 AM

All replies

  • Hi,

    You could develop a plugin on pre create of Account technology details entity where you can check if one record already associated with account then you can throw InvalidPluginExecutionException that will throw an error message and stop the record creation process.


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    • Proposed as answer by RameshwariSah Monday, December 9, 2013 9:30 AM
    Monday, December 9, 2013 7:33 AM
  • Hi,

    Can I do any control by using java script or 1: N relationship or N: 1 relationship.  Please help

    Regards,

    Noushad


    pnoushu@hotmail.com

    Monday, December 9, 2013 7:50 AM
  • Yes, You could also write JS code on OnSave of Account technology details entity where you could also check if already record exist then show alert message and prevent save operation.

    http://community.dynamics.com/crm/b/crmmitchmilam/archive/2011/05/06/crm-2011-canceling-the-save-operation.aspx


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    • Proposed as answer by RameshwariSah Monday, December 9, 2013 9:30 AM
    Monday, December 9, 2013 8:00 AM
  • Hi,

    I have seen below codes in your reply.  Please let me know whether I have to write a code to check the Account technology details of account is existing or not.

    Regards,

    function Form_onsave(executionObj)
    {
        var shouldSave = true;

        if (shouldSave)
        {
            alert("Unable to save because of some reason or the other.");

            executionObj.getEventArgs().preventDefault();
        }
    }

     


    pnoushu@hotmail.com

    Monday, December 9, 2013 1:34 PM
  • Yes, that's what you were looking. use REST or SOAP to check record already exist or not.

    http://crm2011odatatool.codeplex.com/

    http://msdn.microsoft.com/en-us/library/gg309461.aspx


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Monday, December 9, 2013 11:53 PM
  • Hi,

    I am checking the Account technology details of account is existing or not by using the below mentioned code. if the record is existing then it is working properly. But it the record is not available it is giving the error as shown the screen-shot.  Even it is not allowing to check null value. Please help me to solve this issue

    function customerid_onchange()
    {
    if (crmForm.all.new_accountid.DataValue != null && crmForm.all.new_accountid.DataValue[0] != null)
    {

    var buXml = GetRelatedaccounts();
    alert(buXml);
    if(buXml != null) - NO ERROR
     {
     alert("111");
    var buNodes = buXml.selectNodes("//BusinessEntity/q1:new_avcreatedby");
    alert(buNodes);
    if(buNodes != null ) - NO ERROR
    alert("2222");   
      {
                                        if( (buNodes[0].text)  != null )    - ERROR FROM HERE
                                                       alert(buNodes[0].text);
                             { alert("available"); }                                                                        
             }

     

     


     }


    }

    }
    function GetRelatedaccounts()
    {    var accountID= crmForm.all.new_accountid.DataValue[0].id;   
         var xml = "" +
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
        GenerateAuthenticationHeader()  + 
        " <soap:Body>" +
        "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
        "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+
        " xsi:type='q1:QueryExpression'>"+
        " <q1:EntityName>new_accounttechnologydetails</q1:EntityName>" +
        " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
        " <q1:Attributes>" +
        " <q1:Attribute>new_avcreatedby</q1:Attribute>" +
        " </q1:Attributes>" +
        " </q1:ColumnSet>" +
        " <q1:Distinct>false</q1:Distinct>" +
        " <q1:Criteria>" +
        " <q1:FilterOperator>And</q1:FilterOperator>" +
        " <q1:Conditions>" +
        " <q1:Condition>" +
        " <q1:AttributeName>new_accountid</q1:AttributeName>" +
        " <q1:Operator>Equal</q1:Operator>" +
        " <q1:Values>" +
        " <q1:Value xsi:type=\"xsd:string\">" + accountID + "</q1:Value>" +
        " </q1:Values>" +
        " </q1:Condition>" +
        " </q1:Conditions>" +
        " </q1:Criteria>" +
        " </query>" +
        "</RetrieveMultiple>"+
        " </soap:Body>" +
        "</soap:Envelope>" +
        "";

        var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
        xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);

        var resultXml = xmlHttpRequest.responseXML;
        return resultXml;
    }


    pnoushu@hotmail.com

    Wednesday, December 11, 2013 6:11 AM