Forum Discussion

CharleneDougal1's avatar
CharleneDougal1
Qrew Member
10 months ago

How to check if record field is empty in API_DoQuery

When I execute API_DoQuery in the Code Page I get the following XML results. detail_note is empty. However,  $(this).find("detail_note").text() returns 8 159 True www.yahoo.com 1689364909773 which are the values of the fields below.   Does anyone have a suggestion on how check if a field is empty?
 
<qdbapi>
<action>API_DoQuery</action>
<errcode>0</errcode>
<errtext>No error</errtext>
<dbinfo>
<name>PDA Supporting Documents</name>
<desc/>
</dbinfo>
<variables> </variables>
<chdbids> </chdbids>
<record>
<detail_note/>
<support_document/>
<record_id_>8</record_id_>
<related_pda_support_document___pda_record_id>159</related_pda_support_document___pda_record_id>
<iscurrentuserrecordowner>True</iscurrentuserrecordowner>
<support_url>www.yahoo.com</support_url>
<update_id>1689364909773</update_id>
</record>
</qdbapi>


------------------------------
Charlene Dougall
------------------------------

2 Replies

  • Hi Charlene!

    I'd recommend using the RESTful JSON Run Query API instead. It'll provide more clarity on the blank fields you mention, in addition to generally being easier to navigate than XML.



    ------------------------------
    Ryan Pflederer
    ------------------------------
  • Hello Charlene,

    It's a bit tricky to provide a solid answer here without seeing the general structure and logic of your code.

    In general, to check for empty tags with jQuery, you first need to parse the XML. Then you can iterate through each tag and check if it's empty (self-closing) like "<detail_note/>. 

    Here's a simple script to help you get started:

    var xmlDoc = $.parseXML(XMLresponse);
    $(xmlDoc).find('*').each(function() {
       if ($(this).is(':empty')) {
          console.log("Empty field found: " + this.nodeName);
       }
    }

    The above script does the following:

    • Creates a variable that stores the API Response using the parseXML() function.
    • Finds all the tags using find() function and then iterates through them.
    • Checks each node if is empty (no child nodes or text).
    • Prints on the console the tag name. You can perform any action here with the returned information

    Hope that helps!



    ------------------------------
    Apostolos Giatsidis
    ------------------------------