<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/discussions/f/process/19621/find-null-values-in-text-doc-from-template-json-payload</link><description>We have a nightly process that aggregates transactions and sends a JSON payload to an external system 
 Problem: 
 There are times when the payload contains a null value, shown below in RED. In most cases, there was transaction data in the table, but</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76742?ContentTypeID=1</link><pubDate>Fri, 25 Sep 2020 14:59:12 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b8218fa7-9231-477a-a716-907629bec6dc</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;What I would do, if this is run directly in the text doc from template node, is move it to a prior script task and save the json value here into a process variable, say pv!jsonOutput.&amp;nbsp; That process variable can then be used in the text doc from template node, and you can also send the process variable into the rule I suggested earlier with a!fromJson(pv!jsonOutput).&amp;nbsp; This will create a second variable containing only the blank ([]) rows to use in a follow-up email node and/or debugging, if that makes sense.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;1) Script Task, create initial json -&amp;gt; pv!jsonOutput&lt;br /&gt;2) Script Task, use a!fromJson(pv!jsonOutput) input to new rule suggested here -&amp;gt; pv!jsonBlanks&lt;br /&gt;3) Process text doc to template and send primary output with pv!jsonOutput&lt;br /&gt;4) Email and/or log pv!jsonBlanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76715?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2020 16:15:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0077b66c-839b-4f1e-8113-7549a499f706</guid><dc:creator>beHumble</dc:creator><description>&lt;p&gt;The nightly process with the text doc from template is populating the json template with the following below:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will re-iterate that the transactions are showing in the table, but somewhere during the creation of the json, these values end up blank, and the json is sent to an external system.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;with(&lt;br /&gt; local!pendingProcessingTotalCount: rule!CBP_getStagingBillingTransaction(&lt;br /&gt; processingStatus: cons!CBP_STAGING_PROCESSING_STATUS_P,&lt;br /&gt; pagingInfo: a!pagingInfo(1, 0),&lt;br /&gt; isReturnDatasubset: true&lt;br /&gt; ).totalCount,&lt;br /&gt; local!pendingProcessingTransactions: a!flatten(&lt;br /&gt; a!forEach(&lt;br /&gt; items: enumerate(&lt;br /&gt; roundup(local!pendingProcessingTotalCount/1000, 0)&lt;br /&gt; ),&lt;br /&gt; expression: rule!CBP_getStagingBillingTransaction(&lt;br /&gt; pagingInfo: a!pagingInfo(&lt;br /&gt; startIndex: 1 + (fv!item*1000),&lt;br /&gt; batchSize: 1000&lt;br /&gt; ),&lt;br /&gt; processingStatus: cons!CBP_STAGING_PROCESSING_STATUS_P&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt; ),&lt;br /&gt; local!chargeLineTotalCount: rule!CBP_getViewChargeLineProcessingStatus(&lt;br /&gt; processingStatus: cons!CBP_STAGING_PROCESSING_STATUS_P,&lt;br /&gt; pagingInfo: a!pagingInfo(1, 0),&lt;br /&gt; isReturnDatasubset: true&lt;br /&gt; ).totalCount,&lt;br /&gt; local!pendingProcessingChargeLines: a!flatten(&lt;br /&gt; a!forEach(&lt;br /&gt; items: enumerate(&lt;br /&gt; roundup(local!chargeLineTotalCount/1000,0)&lt;br /&gt; ),&lt;br /&gt; expression: rule!CBP_getViewChargeLineProcessingStatus(&lt;br /&gt; processingStatus: cons!CBP_STAGING_PROCESSING_STATUS_P,&lt;br /&gt; pagingInfo: a!pagingInfo(&lt;br /&gt; startIndex: 1 + (fv!item*1000),&lt;br /&gt; batchSize: 1000&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt; ),&lt;br /&gt; if(&lt;br /&gt; rule!APN_isEmpty(local!pendingProcessingTransactions), {&amp;quot;[]&amp;quot;} , &lt;br /&gt; a!toJson(&lt;br /&gt; {&lt;br /&gt; {&lt;br /&gt; a!forEach(&lt;br /&gt; items: local!pendingProcessingTransactions,&lt;br /&gt; expression: {&lt;br /&gt; vanPoolID: fv!item.vanpool_id,&lt;br /&gt; customerID: fv!item.customer_id,&lt;br /&gt; customerName: fv!item.customer_name,&lt;br /&gt; itemID: fv!item.item_id,&lt;br /&gt; unitNumber: fv!item.unit_number,&lt;br /&gt; groupBranch: fv!item.gpbr,&lt;br /&gt; deptID: fv!item.department_id,&lt;br /&gt; chargeYear: fv!item.charge_year,&lt;br /&gt; chargeMonth: fv!item.charge_month,&lt;br /&gt; badDebtDate: rule!GLB_convertDateToInternationalFormat(fv!item.bad_debt_date),&lt;br /&gt; coordinatorFirstName: fv!item.coordinator_first_name,&lt;br /&gt; coordinatorLastName: fv!item.coordinator_last_name,&lt;br /&gt; transactionID: fv!item.staging_billing_transaction_id,&lt;br /&gt; isAccountSold: fv!item.is_account_sold,&lt;br /&gt; chargeLines: {&lt;br /&gt; a!forEach(&lt;br /&gt; items: index(&lt;br /&gt; local!pendingProcessingChargeLines,&lt;br /&gt; wherecontains(&lt;br /&gt; fv!item.staging_billing_transaction_id,&lt;br /&gt; index(local!pendingProcessingChargeLines, &amp;quot;staging_billing_transaction_id&amp;quot;, null)&lt;br /&gt; ),&lt;br /&gt; null&lt;br /&gt; ),&lt;br /&gt; expression: {&lt;br /&gt; chargeType: fv!item.charge_type,&lt;br /&gt; taxType: fv!item.tax_type,&lt;br /&gt; amount: fv!item.amount,&lt;br /&gt; description: fv!item.description,&lt;br /&gt; account: fv!item.tax_account_id,&lt;br /&gt; paymentType: fv!item.payment_type,&lt;br /&gt; paymentName: fv!item.payment_name,&lt;br /&gt; invoiceDate :rule!GLB_convertDateToInternationalFormat(fv!item.invoice_date),&lt;br /&gt; chargeLineID: fv!item.staging_billing_charge_line_id,&lt;br /&gt; primaryEntityID: fv!item.primary_entity_id,&lt;br /&gt; secondaryEntityID: fv!item.secondary_entity_id,&lt;br /&gt; chargeLineTimestamp: rule!GLB_convertDateTimeFormatwithTimeZone(fv!item.charge_line_timestamp)&lt;br /&gt; }&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; }&lt;br /&gt; )&lt;br /&gt; }&lt;br /&gt; }&lt;br /&gt; )&lt;br /&gt; )&lt;br /&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76714?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2020 15:36:10 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9c59ca2f-4ba8-4c57-8f38-8bffc90eb980</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;If the JSON is stored within a document, you would need to parse&amp;nbsp;out the contents prior to the rule call as AFAIK there are no SAIL capabilities to parse text files.&amp;nbsp; However there is a plugin that might be used in this case, to&amp;nbsp;retrieve the JSON values from the document:&lt;/p&gt;
&lt;p&gt;&lt;a href="/b/appmarket/posts/text-file-reader"&gt;Text File Reader&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note I do not have any experience with that plugin, don&amp;#39;t believe we&amp;#39;ve had this use case internally.&lt;/p&gt;
&lt;p&gt;Otherwise,&amp;nbsp;I&amp;#39;m wondering if there could be extra processing included in the mechanism that creates the JSON payload - such as a validation step prior to writing it to the document.&amp;nbsp; Can you expand on how your process creates the JSON payload?&amp;nbsp; Directly into a text file?&amp;nbsp; Or is there an additional rule being utilized where this new mechanism could be injected, etc?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76713?ContentTypeID=1</link><pubDate>Thu, 24 Sep 2020 13:22:44 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dde87178-d392-4ebd-9fa2-e608dab34b80</guid><dc:creator>beHumble</dc:creator><description>&lt;p&gt;Can the local!data input be the actual json doc, or does it need to be something else that can be evaluated in flight?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76676?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 17:47:38 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:e3bb43d2-a2dd-4dda-9ef9-287b8ed53a62</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;Best case you would create this as a rule with local!data being an input parameter vs a local variable.&amp;nbsp; The rule could be called from a Script task -&amp;gt; Save into a PV, or you could call it as an Input variable on the Data tab of your Send Email node, then utilizing the ac! value of the variable vs the pv! value which it would be if you saved it with a proceeding script task.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Feel free to post additional screen shots, etc, here if you have difficulty with the config.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76675?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 17:41:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:994737f7-620e-4cd0-ba89-460268ea3806</guid><dc:creator>beHumble</dc:creator><description>&lt;p&gt;Thank you Chris! Would I use a script node for this, or some other node within the process?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Find Null Values in text doc from template (JSON payload)</title><link>https://community.appian.com/thread/76673?ContentTypeID=1</link><pubDate>Wed, 23 Sep 2020 17:16:15 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:36c20ede-d721-4f11-af38-de0962bfa3aa</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;You should be able to use a cleaning rule such as below.&amp;nbsp; This example would handle multiple values to search for, null, &amp;quot;[]&amp;quot; etc.&amp;nbsp; Essentially ignores the good rows and builds a list of the empty rows (dictionary) for exporting via email, etc.&amp;nbsp; local!data would switch to your input combined with a!fromJSON().&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;a!localVariables(
  local!emptyValuesToSearch: {null,&amp;quot;[]&amp;quot;},
  local!data: {
    {PoolID:&amp;quot;62VP-00xxxx&amp;quot;,customerID:&amp;quot;178xxxxx&amp;quot;,customerName:&amp;quot;East Central &amp;quot;,itemID:&amp;quot;62VP-00xxxx-AUG-2020&amp;quot;,transactionID:513906,chargeLines:&amp;quot;[]&amp;quot;},
    {PoolID:&amp;quot;72VP-00xxxx&amp;quot;,customerID:&amp;quot;278xxxxx&amp;quot;,customerName:&amp;quot;Central &amp;quot;,itemID:&amp;quot;72VP-00xxxx-AUG-2020&amp;quot;,transactionID:513907,chargeLines:&amp;quot;abcd&amp;quot;},
    {PoolID:&amp;quot;82VP-00xxxx&amp;quot;,customerID:&amp;quot;378xxxxx&amp;quot;,customerName:&amp;quot;East &amp;quot;,itemID:&amp;quot;82VP-00xxxx-AUG-2020&amp;quot;,transactionID:513908,chargeLines:null}
  },
  
  reject(
    fn!isnull,
    a!forEach(
      items: local!data,
      expression: {
        if(
          contains(local!emptyValuesToSearch,tostring(property(fv!item,&amp;quot;chargeLines&amp;quot;))),
          {
            PoolID: property(fv!item,&amp;quot;PoolID&amp;quot;,null),
            transactionID: property(fv!item,&amp;quot;transactionID&amp;quot;,null)
          },
          null
        )
      }
    )
  )
  
  /* -&amp;gt; Send in an email */
)&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>