I am trying to loop through a CDT and replace any null values with 0.

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 in which I want to loop through and replace nulls*/

My "rule!ReplaceNulls" is as follows (currently I am just trying to get 1 field to work in the CDT, but this will end up being 3 fields)
={
if(isnull(ri!BuyerSeller.feeAmount),0,ri!BuyerSeller.feeAmount)
}

I keep receiving an error about "Invalid index: Cannot index property "buyerProject" of type Text into type Number (Decimal)".
buyerProject is the first element of my CDT, but this is not one of the fields I care to parse through and check for nulls. How can I loop through a CDT and replace nulls values? Thanks

OriginalPostID-202277

OriginalPostID-202277

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer
    Hi John,
    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,
    1. If you need a single field value to be replaced then you can use the following expression while saving - a!save(<CDT>.<field>, rule!replaceNulls(<CDT>)).
    2. If you are not sure about the number of fields then prepare the whole CDT using 'type!<CDT>'() and configure each field value similar to this expression - if(isnull(ri!<CDT>.<field>),<replacementValue>,ri!<CDT>.<field>). For more details please check the below example for your reference to prepare CDT.
    'type!{name_space}CDT'(
    field1:if(isnull(ri!<CDT>.<field1>),<replacementValue>,ri!<CDT>.<field1>),
    field2:if(isnull(ri!<CDT>.<field2>),<replacementValue>,ri!<CDT>.<field2>)
    )
Reply
  • 0
    Certified Senior Developer
    Hi John,
    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,
    1. If you need a single field value to be replaced then you can use the following expression while saving - a!save(<CDT>.<field>, rule!replaceNulls(<CDT>)).
    2. If you are not sure about the number of fields then prepare the whole CDT using 'type!<CDT>'() and configure each field value similar to this expression - if(isnull(ri!<CDT>.<field>),<replacementValue>,ri!<CDT>.<field>). For more details please check the below example for your reference to prepare CDT.
    'type!{name_space}CDT'(
    field1:if(isnull(ri!<CDT>.<field1>),<replacementValue>,ri!<CDT>.<field1>),
    field2:if(isnull(ri!<CDT>.<field2>),<replacementValue>,ri!<CDT>.<field2>)
    )
Children
No Data