FetchXML with JavaScript in CRM 4.0

Unanswered FetchXML with JavaScript in CRM 4.0

  • 2012年5月11日 21:03
     
     

    Dear all!

    I'm trying to get data from another entity to check an attribute. So I create a fetchxml query to get the results... I tried by diferent ways and there is one that can populate this data to a lookupfield that I've created... What I need to do is count if there is any result...

    This is the code I have on field customerid:

    //Begin

    if (crmForm.all.customerid.DataValue == null) { return; }

    crmForm.all.new_verificadordekctid.lookupbrowse = 1;

    var str = "<fetch mapping='logical'><entity name='account'><filter><condition attribute='accountid' operator='eq' value=' " + crmForm.all.customerid.DataValue[0].id + " '/></filter><filter type='and'><condition attribute='new_categoria_kct' operator='eq' value='1'/></filter></entity></fetch>";

    crmForm.all.new_verificadordekctid.AddParam("search",str);

    //End

    When I go to the new_verificadordekctid I can check if it is a result or not, but I need to count it on the code...

    Is there any way to check if this query has any result, so I can perform another thing within this code???

    Kindest regards!!

    Thanks and happy weekend!

    Pablo

すべての返信

  • 2012年5月11日 21:39
     
     

    I prefer you to use Daniel Cai Javascript to do the same and get the count
    Its really easy to use. and also works with 2011

    if (crmForm.all.customerid.DataValue == null) { return; }


    var str = "<fetch mapping='logical'>"+
    "<entity name='account'>"+
    "<attribute name='lastname' />" +
    "<filter>"+
    "<condition attribute='accountid' operator='eq' value=' " + crmForm.all.customerid.DataValue[0].id + " '/>"+
    "</filter><filter type='and'>"+
    "<condition attribute='new_categoria_kct' operator='eq' value='1'/>"+
    "</filter>"+
    "</entity>"+
    "</fetch>";


    var fetchedAccounts = CrmServiceToolkit.Fetch(fetchXml);

    alert(fetchedAccounts.length);
    alert(fetchedAccounts[0].getValue('lastname'));
    alert(fetchedAccounts[0].getValue('firstname'));

    Just Paste the Toolkit file here
    If you need more information please let me know


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!




  • 2012年5月21日 21:06
     
     

    Dear Mubasher,

    Thank you very much for your answer and for your recommendation.

    Now I have to deploy the CrmServiceToolkit, so I found that there is some ways to do that, can you give another clue on this??? Which is your recommended way to load the toolkit??

    Kindest regards,

    Pablo

  • 2012年5月22日 10:09
     
     

    Thats great Pablo Gomez.
    Download the SDK
    you will find a file named CrmServiceToolkit.
    Open the file in any text editor.
    just copy the toolkit and paste under you functions 
    i.e
    function test()

    {

    }
    Paste your toolkit here.

    If you need more information please let me know.


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
    Mubasher Sharif
    Check out my about.me profile!
    http://mubashersharif.blogspot.com
    Linked-In Profile
    Follow me on Twitter!