locked
how to check the existing of record without using primary key RRS feed

  • Question

  • Hi,

    I have created custom entity namely Technology wich is associated with account entity.  I want to create only one record of technoloy per account. So I need to check the Technology recored of account is existing or not before creating technology entity by using java script. but accountid is not primary key in Technology entity.  So please send me java script to find existing of record using field other than primay key.

    Regards,

    Noushad


    pnoushu@hotmail.com

    Wednesday, December 11, 2013 6:17 AM

Answers

All replies

  • Hello Noushad,

    You don't need primary entity id here to validate as you want to check if there is any technology record exists which is related to current account or not, you need to use retrievemultiple here, check this for JS code.


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Proposed as answer by HIMBAPModerator Wednesday, December 11, 2013 6:38 AM
    Wednesday, December 11, 2013 6:38 AM
    Moderator
  • 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 7:44 AM
  • Hello,

    You should check result set length in order to validate if result found or not, please check this


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    • Marked as answer by P Noushad Monday, December 23, 2013 1:14 PM
    Wednesday, December 11, 2013 8:02 AM
    Moderator