Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Select One with For-Each Not Reflecting Observable Array Values

DaveArchFeb 13 2020 — edited Feb 14 2020

Hi Community

Jet Version: 8.0

We are using Select One with For-Each bound to an observable array to populate the list.

When an action is performed in the page, we need to replace all values in the list. The problem we are finding is that when the values in the underlying observable array are replaced, the new values are appended to the top of the list rather than being replaced. The for-each is stamping the DOM with new elements as they are added to the array.

The code is below but here is a JS Fiddle showing the issue:

https://jsfiddle.net/david_archbold/rg301qp7

Observe how the initial list is populated with 3 values. If you click the 'Change List Values', the 'Values' region shows that the array is replaced with a different data set however the Select One component contains the original values and the new values. If you keep clicking 'Change List Values' you will see the list grow.

list_issue_1.PNG

list_issue_2.PNG

The question is how do we replace the entire set of values in this scenario and avoid the for-each adding values to the list?

The effect is not seen if we use the 'options' attribute on the Select One component however we need to use for-each for a another reason that I won't go into here.

View Model:

let ViewModel = function () {

    const self = this;

    self.listSet = 0;



    self.listValue = ko.observable();

    self.listValueArray = ko.observableArray(\[

        {value: "HOMER", label: "Homer Simpson"},

        {value: "MARGE",label: "Marge Simpson"},

        {value: "BART", label: "Bart Simpson"}

    \]);



    self.changeValues = function () {



        self.listValueArray.removeAll();



        if (self.listSet == 0) {



            self.listValueArray(\[

                {value: "LIST", label: "Lisa Simpson"},

                {value: "MAGGIE",label: "Maggie Simpson"}

            \]);



            self.listSet = 1;



        } else {

            self.listValueArray(\[

                {value: "HOMER", label: "Homer Simpson"},

                {value: "MARGE",label: "Marge Simpson"},

                {value: "BART", label: "Bart Simpson"}

            \]);

        }

        document.getElementById("listvalues").refresh();

    }



};

HTML:

<div id="container">

\<oj-form-layout id\="listform" label-edge\="start" direction\="column"\>



    \<oj-label for\="listvalues" show-required\>My List\</oj-label>

    \<oj-select-one id\="listvalues" value\="{{listValue}}" required placeholder\="" style\="max-width:22em"\>

        \<oj-bind-for-each data\="\[\[listValueArray\]\]"\>

            \<template>

                \<oj-option value\="\[\[$current.data.value\]\]"\>

                    \<span>

                        \<oj-bind-text value\="\[\[$current.data.label\]\]"\>\</oj-bind-text>

                    \</span>

                \</oj-option>

            \</template>

        \</oj-bind-for-each>

    \</oj-select-one>



\</oj-form-layout>



\<oj-button on-oj-action\='\[\[changeValues\]\]'\>

    Change List Values

\</oj-button>



\<div class\="oj-flex oj-sm-flex-direction-column"\>



    \<h>Values\</h>



    \<oj-bind-for-each data\="\[\[listValueArray\]\]"\>

        \<template>

            \<li>

                \<oj-bind-text value\="\[\[$current.data.value\]\]"\>\</oj-bind-text> : \<oj-bind-text

                    value\="\[\[$current.data.label\]\]"\>\</oj-bind-text>

            \</li>

        \</template>

    \</oj-bind-for-each>



\</div>

</div>

I see that the API Reference states the following for oj-bind-for-each which might explain what we are seeing.

http://https://www.oracle.com/webfolder/technetwork/jet/jsdocs/oj.ojBindForEach.html

"The markup section is duplicated for each array item when element is rendered"

Any help appreciated

This post has been answered by Duncan Mills-Oracle on Feb 13 2020
Jump to Answer

Comments

Cookiemonster76

So loop over the table. Inside the loop build up a string of the text you want in the email.

After the loop check if the string is empty, if it is assign the not exists message

After that call the procedure to send the email.

user12251389

I tried but still had the same issue

Saubhik

user12251389 wrote:

I tried but still had the same issue

What is the exact problem you are facing ?

John Stegeman

You tried and it didn't work? What does "didn't work" mean? What did you try - show us?

user12251389

I have currently 2 records in TRACK_KPI table. When i execute this procedure i am getting 2 emails one for each record. So for example if i have 100 records now in TRACK_KPI table then i will receive 100 emails for each records which i dont want. I want all this records from TRACK_KPI  table send in one email

John Stegeman

Yes, because you send the email in a loop. Don't do that. Instead, build the email content in the loop (hint: store it in a CLOB or varchar2 variable, depending on the potential size) and send the email outside the loop

user12251389

Here is what i have tried :

FOR KPI_TRACK_RUNNING_ROW IN (Select KPI_NAME FROM RATOR_MONITORING.TRACK_KPI)

LOOP

sql='SEND_MAIL_SMTP(

    ''support@leo'',           --Sender

    ''r.d@leo.com'',           --Recipient

    ''PREPROD - KPI NOT RUNNING'',                    --Subject

    ''Below KPIs are not running:''' || KPI_TRACK_RUNNING_ROW.KPI_NAME  --Message

  );

execute immediate l_sql;

END LOOP;

Saubhik
Answer

You need something like

CREATE OR REPLACE PROCEDURE execute_send_mail_smtp AS 

v_kpi varchar2(4000) :=' '; --assuming your kpi_names are not long.

begin

FOR KPI_TRACK_ROW IN (Select KPI_NAME FROM RATOR_MONITORING.TRACK_KPI)

LOOP

  v_kpi :=v_kpi||KPI_TRACK_RUNNING_ROW.KPI_NAME||chr(10);

END LOOP;

SEND_MAIL_SMTP(

    'support@leo.com',           --Sender 

    'r.d@leo.com',           --Recipient 

    'TEST- KPI NOT RUNNING',                    --Subject

    'Below KPIs are not running:' || v_kpi  --Message

  );

end execute_send_mail_smtp;

NOT TESTED.

Marked as Answer by user12251389 · Sep 27 2020
user12251389

How can i build email content outside loop ? I have procedure SEND_MAIL_SMTP also which i cant take it in string ?

John Stegeman

send_mail_smtp takes a parameter. Saubhik gave you an example.

user12251389

I tried your logic it sends email without any data and when i replace

v_kpi := v_kpi||chr(10);

as

v_kpi :=KPI_TRACK_ROW.KPI_NAME||chr(10);

in your logic then it sends an email with only one record but there are two records exist in my table

John Stegeman

Think about it...

Why did you replace Saubhik's code, which looked correct with yours, which is obviously not?

Saubhik

I have edited that portion, but this is not a code writing service and as a professional you should take the idea and write, debug yourself.

user12251389

Now it works thanks but just a small question can i use IF condition in this logic ? Because if there is no records exist in the TRACK_KPI table then its not sending any emai. So if there is nor record exist then i just want to send email as 'NO KPI Tracked'

John Stegeman

and just noticed... why the heck are you using execute immediate to call a stored procedure from PL/SQL? There's no need for that

John Stegeman

You can use any PL/SQL construct you like, including "IF"

user12251389

Yes it was mistake i copy paste and didn't realize

user12251389

I have tried with IF logic and it works now. Just a small question can we send email to more than one Recipient ? When i tried to enter 2 Recipient then it gaves me error as

ora-29279 smtp permanent error 550 user unknown

John Stegeman

Talk to whomever wrote send_mail_smtp, or look at the code yourself and figure it out. Of course SMTP can send mail to more than one recipient, if you do it correctly.

1 - 19

Post Details

Added on Feb 13 2020
2 comments
296 views