<?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>I am trying to loop through a CDT and replace any null values with 0.</title><link>https://community.appian.com/discussions/f/rules/7269/i-am-trying-to-loop-through-a-cdt-and-replace-any-null-values-with-0</link><description>I am trying to loop through a CDT and replace any null values with 0. To test this out, I added a button on my form and upon clicking the button I am executing: a!save(ri!BuyerSeller, apply(rule!ReplaceNulls,ri!BuyerSeller)) /*ri!BuyerSeller is the CDT</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29475?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2016 00:28:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:045ea672-6c0f-4022-948c-848a90e64624</guid><dc:creator>johng373</dc:creator><description>Wanted to follow up about this issue:  I got it to work by installing the &amp;quot;CDT Manipulation&amp;quot; plugin. &lt;a href="https://forum.appian.com/suite/tempo/records/type/components/item/i8BCLGOdlMUpdGVqT-RV7oRg74uEGJO5yIdNklp-1ZtH3F1tosyebSo7rEoKHh1XQ/view/summary"&gt;forum.appian.com/.../summary&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So now on my submit button I have:&lt;br /&gt;a!save(ri!BuyerSeller, apply(rule!ReplaceNulls,ri!BuyerSeller)),&lt;br /&gt;&lt;br /&gt;My rule!ReplaceNulls is as follows:  (input is my CDT (Any Type))&lt;br /&gt;={&lt;br /&gt;&lt;br /&gt;  updatecdt(&lt;br /&gt;     ri!BuyerSeller,&lt;br /&gt;     {  &lt;br /&gt;        feeAmount: if(isnull(ri!BuyerSeller.feeAmount),0,ri!BuyerSeller.feeAmount),&lt;br /&gt;        totalDollarAmt: if(isnull(ri!BuyerSeller.totalDollarAmt),0,ri!BuyerSeller.totalDollarAmt),&lt;br /&gt;        totalHours: if(isnull(ri!BuyerSeller.totalHours),0,ri!BuyerSeller.totalHours)&lt;br /&gt;     }&lt;br /&gt;     )&lt;br /&gt;}&lt;br /&gt;Thanks everyone for your ideas, help, and patience.  The learning curve is slowly getting smaller.  :)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29445?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 03:11:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9428e494-ab44-45a7-898c-25ed098d6200</guid><dc:creator>Jin Pheh</dc:creator><description>Ok so time for a sanity check - make sure that nothing on the output side of the task node is overwriting the feeAmount field and then check the process history to confirm what your task node is actually spitting out.&lt;br /&gt;&lt;br /&gt;Second your a!save statement should (I think) be:&lt;br /&gt;&lt;br /&gt;a!save(ri!BuyerSeller.feeAmount,updateArray(ri!BuyerSeller.feeAmount,wherecontains(todecimal(null()), ri!BuyerSeller.feeAmount),0))&lt;br /&gt;&lt;br /&gt;My test case wrapped the values in &amp;quot;toDecimal&amp;quot; because it was a test case and I wanted to confirm that my technique worked on decimals.  In your case you have a real honest to goodness CDT with a strongly typed field present so you don&amp;#39;t need to wrap feeAmount in toDecimal().&lt;br /&gt;&lt;br /&gt;Also, you shouldn&amp;#39;t be trying to update the entire ri!BuyerSeller object, just the ri!BuyerSeller.feeAmount field.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29444?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 02:52:34 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5d8ef466-276c-40de-acbd-885852aae5e5</guid><dc:creator>johng373</dc:creator><description>Your test code worked for me.  I saw the null values get updated to 0 and the non null values stayed in tact.  I am trying this on a Task which is currently running within a process model.  One silly question I have is how would I get &amp;quot;toDecimal&amp;quot; to be a part of my feeAmount?  The feeAmount field type is a Number (Decimal) but the values look like this:&lt;br /&gt;[ID=, &lt;br /&gt;requestID=8375, &lt;br /&gt;buyerProject=1234,&lt;br /&gt;buyerTask=123, &lt;br /&gt;totalDollarAmt=23, &lt;br /&gt;totalHours=0, &lt;br /&gt;sellerProject=, &lt;br /&gt;sellerTask=, &lt;br /&gt;feeAmount=],&lt;br /&gt;[ID=, &lt;br /&gt;requestID=8375, &lt;br /&gt;buyerProject=12345, &lt;br /&gt;buyerTask=1234, &lt;br /&gt;totalDollarAmt=, &lt;br /&gt;totalHours=, &lt;br /&gt;sellerProject=, &lt;br /&gt;sellerTask=, &lt;br /&gt;feeAmount=44]&lt;br /&gt;&lt;br /&gt;So, if I have the following code in my a!save():&lt;br /&gt; a!save(ri!BuyerSeller,updateArray(ri!BuyerSeller.feeAmount,wherecontains(todecimal(null()), todecimal(ri!BuyerSeller.feeAmount)),0))&lt;br /&gt;I now receive an error indicating: Invalid index: &amp;quot;Cannot index property &amp;#39;buyerProject&amp;#39; of type Text into type Number (Decimal).&amp;quot;  I must be missing something big here.  :)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29442?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 01:52:24 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dff92ff6-a9ac-464f-904f-fe1343fe1321</guid><dc:creator>Jin Pheh</dc:creator><description>Interesting - I just tried another test with dummy objects and it updates only the nulls to zero as expected (See below).  &lt;br /&gt;&lt;br /&gt;Stupid question here but are you testing this in the interface editor or are you running a process model and clicking on the submit within a real task?  Also, does the test code below work for you when you try it in a new rule?&lt;br /&gt;&lt;br /&gt;------------&lt;br /&gt;&lt;br /&gt;load(&lt;br /&gt;  local!test: {&lt;br /&gt;    {Id:1, feeAmount: toDecimal(1)},&lt;br /&gt;    {Id:2, feeAmount: toDecimal(2)},&lt;br /&gt;    {Id:3, feeAmount: toDecimal(null())},&lt;br /&gt;    {Id:4, feeAmount: toDecimal(12.31)},&lt;br /&gt;    {Id:5, feeAmount: toDecimal(null())},&lt;br /&gt;    {Id:6, feeAmount: toDecimal(null())}&lt;br /&gt;  },&lt;br /&gt;  updateArray(local!test.feeAmount, wherecontains(todecimal(null()), todecimal(local!test.feeAmount)), 0)&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29441?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 01:50:22 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:c929a3fd-2b7b-49bb-9f33-0829b01b5685</guid><dc:creator>johng373</dc:creator><description>Yes, within my saveInto parameter, I have the following:&lt;br /&gt; saveInto:{&lt;br /&gt;        ri!isClicked,&lt;br /&gt;        a!save(ri!BuyerSeller.feeAmount,updateArray(ri!BuyerSeller.feeAmount,wherecontains(todecimal(null()), ri!BuyerSeller.feeAmount),0))&lt;br /&gt;      }&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29440?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 01:48:43 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:f6c67b64-433c-4f26-97f1-ea0bc2163598</guid><dc:creator>Jin Pheh</dc:creator><description>Is the save call with updateArray() at the end of the saveInto array?&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29439?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 01:45:57 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5dd47d40-9db9-445a-b833-448612563ec9</guid><dc:creator>johng373</dc:creator><description>I tried the following:&lt;br /&gt;a!save(ri!BuyerSeller.feeAmount,updateArray(ri!BuyerSeller.feeAmount,wherecontains(todecimal(null()), ri!BuyerSeller.feeAmount),0))&lt;br /&gt;&lt;br /&gt;and received the same result (All indexes get updated to 0).  I should mention that this CDT has many more fields within it.  I was only trying to update 1 field within the CDT at first just to learn how to loop through a CDT and update specific indexes.  Still just trying to figure out how to update a specific index using a!save().  The reason I am using a!save() is because I want to update these null values when a user clicks the submit button.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29438?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2016 00:09:03 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:005d8c70-c4fb-413f-bb33-29c93fecf85e</guid><dc:creator>Jin Pheh</dc:creator><description>Instead of using an apply function how about just leveraging the set based nature of expressions?    In the example below I have an arbitrary array of decimals and I&amp;#39;m replacing all nulls with 0&amp;#39;s - all without an apply.  You could run a similar expression on the CDT array at the end of your saveInto set and achieve what, I think, you&amp;#39;re looking for.&lt;br /&gt;&lt;br /&gt;load(&lt;br /&gt;  local!test: todecimal({1, 2, 3, null(), 4, null()}),&lt;br /&gt;&lt;br /&gt;  updateArray(local!test, wherecontains(todecimal(null()), local!test), 0)&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29436?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 23:30:31 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0776ffa7-d98c-4453-a06a-de902774cf12</guid><dc:creator>PhilB</dc:creator><description>In which case, this must be an issue with something else on the form outside of the rule and save that you&amp;#39;ve mentioned. I&amp;#39;ve tested in isolation (see the code below) and the apply of the rule works fine. Can you set up a similar test to make sure your rules work correctly?&lt;br /&gt;&lt;br /&gt;(&lt;br /&gt;  local!buyerSeller: {&lt;br /&gt;    {feeAmount: 12.45},&lt;br /&gt;    {feeAmount: 144.28},&lt;br /&gt;    {feeAmount: null},&lt;br /&gt;    {feeAmount: 44.91}&lt;br /&gt;  },&lt;br /&gt;  apply(&lt;br /&gt;    rule!pb_johng_test,&lt;br /&gt;    local!buyerSeller.feeAmount&lt;br /&gt;  )&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;....where rule!pb_johng_test is:&lt;br /&gt;&lt;br /&gt;(&lt;br /&gt;  ri!feeAmount &amp;gt; 0,&lt;br /&gt;  ri!feeAmount,&lt;br /&gt;  0&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29435?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 23:13:32 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:df7bdc7d-4545-4f1a-8d00-59192fd38e3e</guid><dc:creator>johng373</dc:creator><description>Yes it is a decimal field.  However, the symptom occurs even if the filed is not a decimal.  I tried your suggestion and the same symptom occurred.  (still updating all occurrences of this field within the CDT).&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29430?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 22:02:07 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:9b8df57b-fb1c-42dc-880f-27b9483819b2</guid><dc:creator>PhilB</dc:creator><description>Is ri!BuyerSeller.feeAmount a decimal? Have you tried changing the replace nulls rule to something like:&lt;br /&gt;&lt;br /&gt;if(ri!feeAmount&amp;gt;0,ri!feeAmount,0)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29429?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 21:56:41 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:abeb3504-d707-4653-b3a6-9b77b75d4257</guid><dc:creator>johng373</dc:creator><description>Thanks for the suggestion.  Unfortunately,I receive the same result.  All indices of BuyerSeller.feeAmount are getting updated to &amp;quot;0&amp;quot;.  I also tried this as well to specify the index:&lt;br /&gt;a!save(ri!BuyerSeller.feeAmount, apply(rule!ReplaceNulls(ri!BuyerSeller, index:_),ri!BuyerSeller)&lt;br /&gt;&lt;br /&gt;My rule!ReplaceNulls was changed to:&lt;br /&gt;&lt;br /&gt; if(isnull(ri!BuyerSeller[ri!index].feeAmount),0,ri!BuyerSeller[ri!index].feeAmount)&lt;br /&gt;&lt;br /&gt;However, this solution gave me an error with regards to index.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29428?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 21:39:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:82b75ce9-4ba4-480d-b08c-697e897b7d72</guid><dc:creator>PhilB</dc:creator><description>How about this:&lt;br /&gt;&lt;br /&gt;Button save:&lt;br /&gt;a!save(ri!BuyerSeller.feeAmount, apply(rule!ReplaceNulls,ri!BuyerSeller.feeAmount))&lt;br /&gt;&lt;br /&gt;rule!ReplaceNulls:&lt;br /&gt;if(isnull(ri!feeAmount),0,ri!feeAmount)&lt;br /&gt;&lt;br /&gt;...where rule!ReplaceNulls has a sinlge input of decimal type.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29426?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 19:36:48 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:dd5f6d6a-30e7-4c82-a873-14def3bf3c2d</guid><dc:creator>johng373</dc:creator><description>Sorry, I should have mentioned, In my button a!save() function, I now have:&lt;br /&gt;a!save(ri!BuyerSeller.feeAmount, rule!ReplaceNulls(ri!BuyerSeller))&lt;br /&gt;&lt;br /&gt;I just need to figure out how to not replace the entire CDT if a null value is found.  I only want to replace a specific index if a null value is found.&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29425?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 19:24:05 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:b4b61ab1-24c0-4563-a371-ba18d52e5b4f</guid><dc:creator>johng373</dc:creator><description>Thanks for your responses.  I think I am closer.  I can now find the null values and replace them, however, the null values are getting replaced with a value from a different index of the CDT.&lt;br /&gt;&lt;br /&gt;In my button a!save() function, I now have:&lt;br /&gt;a!save(ri!BuyerSeller.feeAmount, apply(rule!ReplaceNulls,ri!BuyerSeller))&lt;br /&gt;&lt;br /&gt;In my &amp;quot;rule!ReplaceNulls&amp;quot;, I have:&lt;br /&gt;if(isnull(ri!BuyerSeller.feeAmount),0,ri!BuyerSeller.feeAmount)&lt;br /&gt;&lt;br /&gt;Data as it appears before executing the button which calls this code:&lt;br /&gt;BuyerSeller[1].feeAmount: null&lt;br /&gt;BuyerSeller[2].feeAmount: 44.00&lt;br /&gt;&lt;br /&gt;Data as it appears after executing the button which calls the code:&lt;br /&gt;BuyerSeller[1].feeAmount: 0&lt;br /&gt;BuyerSeller[2].feeAmount: 0&lt;br /&gt;&lt;br /&gt;So, this code is kind of working as it is replacing the null value at index 1, however, it should not replace the 44.00 value in index 2.  Can you help point me in the right direction of how I can specify indices or if I even need to?&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29411?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 10:04:28 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:43f54e31-5b43-4055-a5e1-9c6735ac1ad2</guid><dc:creator>kumaraveln</dc:creator><description>You can try replacing rule!ReplaceNulls contents with below code:&lt;br /&gt;&lt;br /&gt;if(&lt;br /&gt;  isnull(ri!BuyerSeller.feeAmount),&lt;br /&gt;  updatecdt(&lt;br /&gt;     ri!BuyerSeller,&lt;br /&gt;     {&lt;br /&gt;        feeAmount: 0&lt;br /&gt;     }&lt;br /&gt;  ),&lt;br /&gt;  ri!BuyerSeller&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29410?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 09:30:02 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0e829e72-3987-4ffc-80e6-88d55e479cdd</guid><dc:creator>nareshs427</dc:creator><description>Hi John,&lt;br /&gt;You were trying to save a decimal value to a CDT type. If you check the rule created for replacing nulls, it actually returns a decimal value. Here are the ways to achieve your requirement based on how many fields you need to replace in a CDT,&lt;br /&gt;1. If you need a single field value to be replaced then you can use the following expression while saving -  a!save(&amp;lt;CDT&amp;gt;.&amp;lt;field&amp;gt;, rule!replaceNulls(&amp;lt;CDT&amp;gt;)).&lt;br /&gt;2. If you are not sure about the number of fields then prepare the whole CDT using &amp;#39;type!&amp;lt;CDT&amp;gt;&amp;#39;() and configure each field value similar to this expression - if(isnull(ri!&amp;lt;CDT&amp;gt;.&amp;lt;field&amp;gt;),&amp;lt;replacementValue&amp;gt;,ri!&amp;lt;CDT&amp;gt;.&amp;lt;field&amp;gt;). For more details please check the below example for your reference to prepare CDT. &lt;br /&gt;&amp;#39;type!{name_space}CDT&amp;#39;(&lt;br /&gt;field1:if(isnull(ri!&amp;lt;CDT&amp;gt;.&amp;lt;field1&amp;gt;),&amp;lt;replacementValue&amp;gt;,ri!&amp;lt;CDT&amp;gt;.&amp;lt;field1&amp;gt;),&lt;br /&gt;field2:if(isnull(ri!&amp;lt;CDT&amp;gt;.&amp;lt;field2&amp;gt;),&amp;lt;replacementValue&amp;gt;,ri!&amp;lt;CDT&amp;gt;.&amp;lt;field2&amp;gt;)&lt;br /&gt;)&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I am trying to loop through a CDT and replace any null values with 0.  &lt;br /&gt;&lt;br</title><link>https://community.appian.com/thread/29403?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2016 03:57:40 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fe9abcbd-497e-4d35-984e-c0f873a8bb13</guid><dc:creator>Tom Ryan</dc:creator><description>It sounds like this would be the expected behavior of apply(). From the docs:&lt;br /&gt;&lt;br /&gt;apply(): Calls a rule or function for each item in a list&lt;br /&gt;&lt;br /&gt;This means that each field in the CDT will be an input to the rule ReplaceNulls. &lt;br /&gt;&lt;br /&gt;With the way that ReplaceNulls is set up, I don&amp;#39;t think you need to use apply() here at all (just pass the entire CDT).&lt;br /&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>