Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By stevensi1018
#813762
I have a dropdown (shipping_address) which which has a sql query like this:
Code: Select all
	WHERE C.ID = @@optional_shipping_client
 
optional shipping client is a suggest control with this query:
Code: Select all
SELECT ID,NAME AS optional_shipping_client FROM TABLE
In a trigger in the task before this task, I set these variables:
Code: Select all
	@@optional_shipping_client_test = $resultClient[1]['ID'];
	@@optional_shipping_client_test_label = $resultClient[1]['NAME'];
	@@optional_shipping_client = $resultClient[1]['ID'];
	@@optional_shipping_client_label = $resultClient[1]['NAME'];
And in Javascript I set them like this (I don,t know why but I lose these values if I don't do this)
Code: Select all
if($("#optional_shipping_client_test").getValue() != "")
  {
      $("#optional_shipping_client").setValue($("#optional_shipping_client_test").getValue());
      $("#optional_shipping_client").setText($("#optional_shipping_client_test_label").getValue());
  }
  
The problem is that when I set the value programmatically , the dropdown shipping_address doesn't have any value. If I remove one character from @@optional_shipping_client and I select the name of the client (in the suggest), it works. If I alert the @@optional_shipping_client it has the same value that the suggest returns and it has the same label.

I don,t understand why I MUST choose a suggest result so the shipping_address appear
#813763
stevensi1018 wrote: I have a dropdown (shipping_address) which which has a sql query like this:
Code: Select all
   WHERE C.ID = @@optional_shipping_client
Do you have "SELECT FIELD1, FIELD2 FROM TABLE " before that in the query?
stevensi1018 wrote:And in Javascript I set them like this (I don,t know why but I lose these values if I don't do this)
Code: Select all
if($("#optional_shipping_client_test").getValue() != "")
  {
      $("#optional_shipping_client").setValue($("#optional_shipping_client_test").getValue());
      $("#optional_shipping_client").setText($("#optional_shipping_client_test_label").getValue());
  }

The problem is that when I set the value programmatically , the dropdown shipping_address doesn't have any value. If I remove one character from @@optional_shipping_client and I select the name of the client (in the suggest), it works. If I alert the @@optional_shipping_client it has the same value that the suggest returns and it has the same label.

I don,t understand why I MUST choose a suggest result so the shipping_address appear
This line of your code:
Code: Select all
$("#optional_shipping_client").setText($("#optional_shipping_client_test_label").getValue());
is overwriting the value which you set with the previous line:
Code: Select all
$("#optional_shipping_client").setValue($("#optional_shipping_client_test").getValue());
You should change your suggest field to a dropdown box.
Unfortunately, setValue() and setText() can't be used to select an option in a suggest box. You need to use a dropdown box.

Note: You can work around this problem by creating a text field and using that text field as your dependent field in the SQL query and use a change event handler to copy the value of the suggest box to the text field. Use $(#field-id).hide() to hide the text field so the user doesn't see it. Do NOT use a hidden field, since hidden fields can't be used in dependent field queries.
Your JavaScript code would be something like this:
Code: Select all
$("#optional_shipping_client_hidden").hide(); //hide text field

$("#optional_shipping_client").setOnchange( function($newVal, $oldVal) {
   $("#optional_shipping_client_hidden").setValue($newVal);
});
 
Then your SQL query would be something like:
Code: Select all
SELECT FIELD1, FIELD2 FROM MYTABLE AS C WHERE C.ID = @@optional_shipping_client_hidden

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]