Skip to main content
manjit.1486
May 29, 2024
Question

Typecast not working

  • May 29, 2024
  • 24 replies
  • 0 views

Hello Everyone,

I am using text() or any  function in type!{urn:com:appian:types}Test'(). But it seems not working. Can anyone suggest how I can do this?

Thanks

24 replies

stefanhelzle0001
May 29, 2024
I am using text() or any  function in type!{urn:com:appian:types}Test'().

What exactly do you mean with this?

- What do you want to achieve?

- What did you do to achieve this?

- What do you observe?

- What is the deviation?

manjit.1486
May 29, 2024

 fn!text(
              fixed(
                abs(
                  sum(
                    index(
                      local!data,"amount",{}
                    )
                  )
                ),
                2
              ),
              "00.00"
            )

The above code I am using for calculate amount. Basically I want values after decimal or format that I mentioned in the code. But when I use above code in type! function it round up the amount.


'type!{urn:com:appian:types:KIO}KIO_DSE_CASE'(
quantity:if(
            rule!GLB_isBlank(
              index(local!data, "bciCalcSplitAmount_dec", {})
            ),
            {},
            fn!text(
              fixed(
                abs(
                  sum(
                    index(
                      local!data,"amount",{}
                    )
                  )
                ),
                2
              ),
              "00.00"
            )
          ),
)

manjit.1486
May 29, 2024

Note: This fixed and fn!text function works properly outside type! function. Please see the below screenshot. But when I used this code in type! it won't work.

shubhama926776
May 29, 2024

What is your end goal? 
Help us with example.

manjit.1486
May 29, 2024

The value comes up 3854611. Basically this is round up value.

But the actual value is 3854611.85

manjit.1486
May 29, 2024

I want this format text(value, "00.00") which is not working inside the  type! function.

mathieud0001
May 29, 2024

it's unclear to me why there are so many manipulations being done on the number.

sum and round should be sufficient to give you a decimal which you can then format anyway you want for presentation using text/fixed or even a!currency(). https://docs.appian.com/suite/help/24.2/recipe-define-a-simple-currency-component.html 

And if you need to store that amount, you will need a decimal field in your Test() Data Type.

manjit.1486
May 29, 2024

Quantity field is decimal type in a database table. I have updated the xsd file as well. But it still not woking.

mathieud0001
May 30, 2024

Would you mind showing us the .xsd file?

I've done some tests on my end putting text/fixed into a decimal field and can't reproduce the issue.

mikes0011
Brainy
May 29, 2024

If you're trying to convert a number to a string, you simply need "toString()".  text() does something altogether separate.

Now if you're really needing to take a decimal and make sure your displayed amount is that decimal with a constant number of places, there are various rules available (check out the Appian Functions documentation for the master list, as always), but one of my favorites is "fixed()", which you feed a number and a "number of places" value and it outputs the decimal with that many places (returning a rendered text value).

manjit.1486
May 29, 2024

After changing datatype from Decimal to Varchar - It worked. However, still wondering if this is good way of returning decimal value with Varchar instead of Decimal. Really appreciate your feedback how better this could handle and where potentially the issue lies. 

mathieud0001
May 30, 2024

I personally wouldn't recommend storing the amount as a varchar. Probably best to find the root cause of this issue.

manjit.1486
May 30, 2024

This is what I am asking. What should I do? Please see below code I am using to achieve.

  a!forEach(
    items: ri!empdetails,
    expression: 
      'type!{urn:com:appian:types:TPR}TPR_TEST'(
        name: fv!item.name,
        joinDate: fv!item.date,
        quantity: if(
          rule!GLB_isBlank(
            index(fv!item, "amount", {})
          ),
          {},
          fn!text(
            fixed(
              abs(
                sum(
                    index(fv!item, "amount", {}),
                )
              ),
              2,             
            ),
            "00.00"
          )
        ),
        account: fv!item.account,
      )
  )

As I said, I have changed datatype from Decimal to Varchar for quantity field. 

It would be appreciated If I get assistance on this.