Digital Assistant and Mobile

Get Involved. Join the Conversation.

Topic

    Pawan Gupta
    Array missing value in attribute how to identify...Answered
    Topic posted October 19, 2019 by Pawan GuptaBlue Ribbon: 750+ Points, tagged Conversational AI, Virtual Assistant, VPA 
    20 Views, 2 Comments
    Title:
    Array missing value in attribute how to identify has_content?
    Summary:
    Array missing value in attribute how to identify has_content?
    Content:

    I have an array "detailsLines" returned by custom component , it is possible that Description attribute may not be present I am trying to catch that and struggling to make it work, below the syntax i am using, what is i am possibly missing

     

    <#if detailsLines.Description.value?has_content> ${detailsLines.Description}\n <#else>no description</#if>

    Best Comment

    Frank Nimphius

    The expression you use is not correct

     

    If the attribute is "Description" then the expression needs to be 

    <#if detailsLines.value.Description?has_content> ${detailsLines.value.Description}\n <#else>no description</#if>

    However, the above expression only works for objects, not arrays. To check an array, you wold iterate over it. So the expression needs to be

    <#if detailsLines.value[index].Description?has_content> ${detailsLines.value[index].Description}\n <#else>no description</#if>

     

    If you se the System.CommonResponse component to print items for the array, then you would use the iteratorVariable and point it to "detailsLines". The expression to use in the System.CommonResponse component would then become

    ${detailsLines.Description?has_content?then(detailsLines.Description, 'No Description')}

     

    Frank

    Comment

     

    • Frank Nimphius

      The expression you use is not correct

       

      If the attribute is "Description" then the expression needs to be 

      <#if detailsLines.value.Description?has_content> ${detailsLines.value.Description}\n <#else>no description</#if>

      However, the above expression only works for objects, not arrays. To check an array, you wold iterate over it. So the expression needs to be

      <#if detailsLines.value[index].Description?has_content> ${detailsLines.value[index].Description}\n <#else>no description</#if>

       

      If you se the System.CommonResponse component to print items for the array, then you would use the iteratorVariable and point it to "detailsLines". The expression to use in the System.CommonResponse component would then become

      ${detailsLines.Description?has_content?then(detailsLines.Description, 'No Description')}

       

      Frank

    • Pawan Gupta

      Thanks for clarifying.