Forum Discussion

CharleneDougal1's avatar
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 1689364909773 which are the values of the fields below.   Does anyone have a suggestion on how check if a field is empty?
<errtext>No error</errtext>
<name>PDA Supporting Documents</name>
<variables> </variables>
<chdbids> </chdbids>

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