Page 1 of 1

Trigger or Javascript??? and the corresponding code

Posted: Sun Jul 18, 2021 5:01 am
by alisoroush7
Hi guys.

The subject is:
I have connected one of my processes to an external sql database through Database Connection( very hard of course due to lack of sql connection!). In my dynaform i have two textbox that are named RefNumber and Value and also i have a button. i want to enter a number in RefNumber and press the button and related value to that number appears in Value (i have that number and its corresponding value in my database that i earlier connected).
So the first question is : Which one should i use ?Trigger or Javascript?
and the second question: what is the code?

Any comment is appreciated.

Re: Trigger or Javascript??? and the corresponding code

Posted: Sun Jul 18, 2021 8:35 pm
by kirkwg
Hi there,

I only can give you direction here as I have no time to prepare any coding as well or you could search any reference codes online.

Method 01:
1/ Use a trigger before dynaform to retrieve all pairs of RefNumber and its Value; save it to a process array variable.
2. Using JS textbox.setOnchange() event, when the textbox value get changing, retrieve the Value from the process array variable, and then textbox.setValue() to set the Value to that Value's textbox. No button is required in this case!

Let m eknow if this design fits you or not? Cheers...

Re: Trigger or Javascript??? and the corresponding code

Posted: Mon Jul 19, 2021 6:03 am
by alisoroush7
kirkwg wrote: Sun Jul 18, 2021 8:35 pm Hi there,

I only can give you direction here as I have no time to prepare any coding as well or you could search any reference codes online.

Method 01:
1/ Use a trigger before dynaform to retrieve all pairs of RefNumber and its Value; save it to a process array variable.
2. Using JS textbox.setOnchange() event, when the textbox value get changing, retrieve the Value from the process array variable, and then textbox.setValue() to set the Value to that Value's textbox. No button is required in this case!

Let m eknow if this design fits you or not? Cheers...
i would like to use second method because i have to enter the RefNumber in dynaform then retrieve the variable but i have a question:
i should right in sql to retrieve my variable from database and save it in a variable then write in javascript with set on change??

Re: Trigger or Javascript??? and the corresponding code

Posted: Mon Jul 19, 2021 8:05 am
by kirkwg
Hi,

Yes, exactly what you wrote and you have to do the logic like below:

1/ Use a trigger to get your array data from your DB table. Save to a process variable array variablee.g. dbResults, say
Array(
array (RefNumber, Value),...)
a. $sql = "SELECT statement";
b. @=dbResults = ExecuteQuery($sql);
c. you may need to serialized the php array into a json string

2/ you need to write JS
$("#RefNumber-id").setOnchange(function(newValue , oldValue){
//write your code here...
a. Based on your newValue search the Value from the dbResults' json string in JS
b. if the Value found then $("#textValue-id").setValue(Value);

})
Good luck...

Re: Trigger or Javascript??? and the corresponding code

Posted: Mon Jul 19, 2021 8:17 am
by alisoroush7
kirkwg wrote: Mon Jul 19, 2021 8:05 am Hi,

Yes, exactly what you wrote and you have to do the logic like below:

1/ Use a trigger to get your array data from your DB table. Save to a process variable array variablee.g. dbResults, say
Array(
array (RefNumber, Value),...)
a. $sql = "SELECT statement";
b. @=dbResults = ExecuteQuery($sql);
c. you may need to serialized the php array into a json string

2/ you need to write JS
$("#RefNumber-id").setOnchange(function(newValue , oldValue){
//write your code here...
a. Based on your newValue search the Value from the dbResults' json string in JS
b. if the Value found then $("#textValue-id").setValue(Value);

})
Good luck...
many thanks for your consideration
i describe my problem in detail in another post, can you please see it?
https://forum.processmaker.com/viewtopic.php?f=44&t=738101

Re: Trigger or Javascript??? and the corresponding code

Posted: Sun Jan 02, 2022 6:20 am
by ljglmail
I'm sure that many of us have had the same problem as I did. You have a page that displays content in a list format and you need to click on a particular line in the list to display different content. I searched high and low for an answer on this, until finally I just started putting it together myself based on what I learned here and there. In this article, we'll look at two methods for this task: using JavaScript or using a trigger.

Toggle Content with JavaScriptLet's start by looking at how it would be done with JavaScript. No surprises here; we simply add an onClick attribute to each list item, which calls a function that changes the appearance of the page:

<ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul>

If you're using jQuery, then your code might look something like this:

$("ul li").click(function(){ //Do Something });

With an ordinary open-ended approach like this, you'd be out of luck if you wanted to use some kind of data source to determine which item was being clicked.

Re: Trigger or Javascript??? and the corresponding code

Posted: Tue Sep 27, 2022 11:23 am
by ABakhsh3241
Fortunately, there are several ways to do it: some require writing code, some use simple arrays and some use methods provided by the JavaScript language. A unique value in an array JS is a value that appears exactly once. If you have an array with three integers, a unique value would be one of those three integers.
javascript find unique values in the array
Code: Select all
// usage example:
var myArray = ['a', 1, 'a', 2, '1'];
var unique = myArray.filter((v, i, a) => a.indexOf(v) === i); 

// unique is ['a', 1, 2, '1']
Source: Codeprozone.com
https://codeprozone.com/code/javascript/55637/Array-unique-values-javascript.html