When defining a new array for a local variable, I would like to separate the values to be stored when the existing array is NULL and when it is not. Is it possible? ローカル変数に新しい配列を定義するとき、既存の配列がNULLのときとそれ以外で格納する値を分けたいです。実現可能でしょうか?

I am always indebted. I have a question for all you kind people.
Store the array obtained from the record type in the first local variable.
Stores a new array that adds part of the value of the first local variable to the second local variable.
This second local variable will be used to display the graph.

The first local variable stores data corresponding to the rule input value, if any. However, in rare cases, the value entered may not exist for the record type being queried. At this time, the value of the first local variable will be [].

Here comes the problem. When defining the value of the second local variable, there is no problem if the first local variable has a value other than []. However, if it is [], the addition process will not be possible and an error will occur. I would like to solve this problem, but are there any appropriate functions or ideas?

When defining the second local function, if I included an IF function or a NULL check, the variable definition did not work. If anyone knows, please let me know. Thank you.

いつもお世話になっています。親切な皆様に質問があります。
1つめのローカル変数に、レコードタイプから取得した配列を格納します。
2つめのローカル変数に、1つ目のローカル変数の値の一部を加算した新しい配列を格納します。
この2つめのローカル変数を、グラフの表示に使用します。

1つめのローカル変数には、ルール入力された値がある場合はそれに応じたデータを格納します。しかしまれに、入力された値がクエリ対象のレコードタイプに存在しないケースがあります。このとき、1つめのローカル変数の値は [] になります。

ここで問題が発生します。2つ目のローカル変数の値を定義するとき、1つめのローカル変数が [] 以外の値であれば問題ありません。しかし[]だった場合は、加算の処理ができずにエラーが発生します。この問題を解決したいのですが、適切な関数や工夫はありますでしょうか?

2つめのローカル関数を定義する際にIF関数やNULLチェックを挟むと変数定義がうまくいきませんでした。もしご存じの方がいれば教えて頂きたいです。よろしくお願いいたします。

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Can you please share the code.And the error message that you are getting

  • 0
    Certified Associate Developer

    You can handle this case with the help of null check while adding.

  • 0
    Certified Senior Developer

     : Can you provide the code what you are trying to achieve: As per my understanding you can easily remove null from both the array and append the value or do other kind of operation with those 2 arrays: below is the code through which we can check the null & remove it. 

    a!flatten(
      a!forEach(
        local!array,
        if(
          a!isNotNullOrEmpty(fv!item),
          fv!item,
          {}
        )
      )
    )

  • 0
    Certified Senior Developer

    hi   could you please share your code snippet, that would help for better understanding

  • 0
    Certified Senior Developer

    Hello  
    If you are trying to add elements to an empty array throws an error.
    Set a default empty array for the first local variable using a!defaultValue().
    append()  the first local variable with desired values in the second local variable.

  • thank you.
    The code can be concisely written as follows.
    a!localVariables(
    local!aaaBbb: a!queryRecordType(...),
    local!aaaBbb2: local!aaaBbb[1]+local!aaaBbb[2]...,

    local!aaaBbb stores the value of the record type, but if there is no data that matches the search conditions, NULL will be stored.

    This variable is used to display the graph, so if it is NULL, I would like to leave it NULL and use the variable. However, if you check NULL before defining local!aaaBbb2, an error will occur.

    Error statement when not checking NULL (value is NULL)
    (occurs only if NULL) is attached.

    ありがとうございます。
    コードを簡潔に記載すると、以下のようになります。
    a!localVariables(
    local!aaaBbb: a!queryRecordType(...),
    local!aaaBbb2: local!aaaBbb[1]+local!aaaBbb[2]...,

    local!aaaBbbにはレコードタイプの値が格納されていますが、検索条件に一致するデータが1件もない場合はNULLが格納されます。

    この変数はグラフの表示に使用するため、NULLの場合はNULLのまま変数を使用したいです。しかしlocal!aaaBbb2の定義前にNULLチェックを入れるとエラーになります。

    NULLチェックを入れない場合のエラー文(値がNULL
    NULLの場合のみ発生)を添付します。

  • thank you.
    If you check NULL when defining a local variable, no error will occur, but all values will be NULL. To write the code concisely, local!aaaBbb contains the record type value or NULL. I want to leave NULL as NULL to convey that "the result is NULL" if NULL is included in order to display it in the final graph. I tried writing the same way with null() and isNullOrEmpty(), but it still returns NULL even if there is a value. Is there a problem with the way I write it? Thank you.

    local!aaaBbb2:
    if(isnull(local!aaaBbb),
    {
    local!yosan[1],
    local!yosan[1]+local!yosan[2],
    ...
    },
    ""
    ),

    ありがとうございます。
    ローカル変数定義時にNULLチェックを入れた場合、エラーにはなりませんが値がすべてNULLになってしまいます。コードを簡潔に記載すると、local!aaaBbbは、レコードタイプの値もしくはNULLが入っています。最終的にグラフに表示するため、NULLが入っている場合は「結果がNULLである」ことを伝えるためNULLはNULLのままにしたいのです。null()やisNullOrEmpty()でも同様に記述してみましたが、やはり値がある場合もNULLとなってしまいます。記述の仕方に問題があるでしょうか?よろしくお願いいたします。

    local!aaaBbb2:
    if(isnull(local!aaaBbb),
    {
    local!yosan[1],
    local!yosan[1]+local!yosan[2],
    ...
    },
    ""
    ),

  • thank you.
    The code I'm trying to achieve is below.
    This is a temporary name, but we will use two local variables: "aaaBbb" and "aaaBbb2". The former is the result of querying the record type, and may contain a value or be NULL, and so far the specifications are as expected. The latter variable is slightly modified for graphical display. There is no problem if the value is obtained from the record type, but if it is NULL, an error occurs when defining "aaaBBB2". It should be noted that this variable is to be displayed on the graph, and if it is NULL, we want it to be displayed as NULL (no corresponding value).

    Thank you for the test code! If I can resolve the error in the NULL part, I'm planning to try repeating the process. Thank you.

    local!aaaBbb2:
    if(isnull(local!aaaBbb),
    {
    local!yosan[1],
    local!yosan[1]+local!yosan[2],
    ...
    },
    ""
    ),

    ありがとうございます。
    達成しようとしているコードは以下の通りです。
    これは仮の名前ですが「aaaBbb」「aaaBbb2」の2つのローカル変数を使用します。前者はレコードタイプをクエリした結果で、値が入っている場合もNULLの場合もあり、ここまでは想定通りの仕様です。後者の変数はグラフ表示のために少し手を加えたものです。レコードタイプから値が取れた場合は問題ないのですが、NULLの場合に「aaaBBB2」定義時にエラーが発生しています。注意すべきなのはこの変数はグラフに表示させるものであり、NULLの場合はNULL(該当の値がありません)で表示させたいことです。

    テストのコードをありがとうございます!もしNULL部分のエラーが解決できた時は、繰り返し処理も実施してみる心づもりです。よろしくお願いいたします。

    local!aaaBbb2:
    if(isnull(local!aaaBbb),
    {
    local!yosan[1],
    local!yosan[1]+local!yosan[2],
    ...
    },
    ""
    ),

  • thank you.
    The code I'm trying to achieve is below.
    This is a temporary name, but we will use two local variables: "aaaBbb" and "aaaBbb2". The former is the result of querying the record type, and may contain a value or be NULL, which is the expected specification.
    If NULL is stored in the former, an error will occur when defining the latter variable. However, a NULL value should remain NULL, and if there is a value, the calculated value should be used. We are struggling to achieve both. I'm thinking of something I can do by embedding expression rules. Thank you.

    local!aaaBbb2:
    if(isnull(local!aaaBbb),
    {
    local!yosan[1],
    local!yosan[1]+local!yosan[2],
    ...
    },
    ""
    ),

    ありがとうございます。
    達成しようとしているコードは以下の通りです。
    これは仮の名前ですが「aaaBbb」「aaaBbb2」の2つのローカル変数を使用します。前者はレコードタイプをクエリした結果で、値が入っている場合もNULLの場合もあり、想定通りの仕様です。
    前者にNULLが格納されていた場合、後者の変数定義時にエラーが発生します。しかし、NULLの値はNULLのまま、値がある場合はその値を計算したものを使用する必要があります。この両者を実現するのに苦心しています。式ルールの埋め込みなどで何とかできないか考え中です。よろしくお願いいたします。

    local!aaaBbb2:
    if(isnull(local!aaaBbb),
    {
    local!yosan[1],
    local!yosan[1]+local!yosan[2],
    ...
    },
    ""
    ),

  • thank you. If you try to add an element to an empty array, an error will be thrown.
    Let's try a!defaultValue() some more! thank you for teaching me.

    ありがとうございます。空の配列に要素を追加しようとするとエラーがスローされるのですね、、
    a!defaultValue() をもう少し試してみます!教えてくれてありがとう。