Skip to main content

Hello,

I am having some troubles with client scripts and client scripts SQL. I am trying to create a client script that will get user_def9. When I run a test, I am able to get an alert for 

  • alert("TEST"); → Working
  • alert(personID); → Working
  • alert(selectedValue + "this is a test")  → Alert only shows “this is a test”
  • alert(personType) → Not working. Shows oobject Object]

 Below is what is in my client script

var screenName=getCurrentScreenName();
var personID=getUserInfo('personId');

var personType = getDBValues("select user_def9 from person where person_id ='JSMITH'");
var selectedValue = getDBValues("SP_USER_ROLE",personID);

alert("TEST");
alert(personID);
alert(selectedValue + "this is a test")
alert(personType)

This is what is in my Client Scripts SQL

select USER_DEF9 from PERSON where PERSON_ID = '{0}'
  1. For the web client only, are you able to use SQL queries within the brackets? or do they require an entry in Client Script SQL that needs to be called?
  2. Why isn't selectedValue showing what I want?

Hi @qquac 

As far as I know, getDBValues returns an array of values.

You will need to specify the array cell and value you wish to retrieve.

You can try one of the following. You will notice it is the same but the second method separates the function.

var selectedValue = getDBValues("SP_USER_ROLE",personID))0].user_def9;

OR


var selectedValue = getDBValues("SP_USER_ROLE",personID);
alert(selectedValuee0].user_def9);

For the query - var personType = getDBValues("select user_def9 from person where person_id ='JSMITH'");

I do not think this is supported in Webclient, as it is expected to have a Client Script SQL is a parameter.

 

Cheers!


Hi @Shneor Cheshin,

This one did not work - no pop ups were generated

var selectedValue = getDBValues("SP_USER_ROLE",personID))0].user_def9;

This one pop ups were generated but it didn’t produce the expected results.

  • alert(selectedValue + "this is a test")  → Alert only shows “this is a test”
var selectedValue = getDBValues("SP_USER_ROLE",personID);
alert(selectedValuee0].user_def9);

I tried adjusting the Client Script SQL to the below and it did populate  the expected results.

select USER_DEF9 from PERSON where PERSON_ID = 'JSMITH'
var selectedValue = getDBValues('SP_USER_ROLE',personID);
alert(selectedValues0].user_def9);

I am curious if it’s because of how the variable is set. Since the personID is a string, does it need to have quotes surrounding it? If so, how do I concatenate this variable with quotes around it?

var selectedValue = getDBValues('SP_USER_ROLE',personID);

 


Hi @qquac 

It means that the query is returning 0 records.

  1. You can and should validate the result. Something like below
    if(selectedValue.length > 0 && isNullOrEmptyString(selectedValue) == true)
    {
    DO SOMETHING...
    }
    else // No value returned
    {
    DO SOMETHING ELSE...
    }
  2. As far as I know, getDBValues() expects an array as parameter. Add the brackets character ‘ ‘ & ‘]’ around the parameter. Also, it can be a list/array, if your SQL client script needs more than 1 variable.
    var selectedValue = getDBValues("SP_USER_ROLE",_personID]),0].user_def9;

    Example of multiple parameters 

    var selectedValue = getDBValues("SP_USER_ROLE",PpersonID,otherParam1,otherParam2])o0].user_def9;

Cheers!


Hi @qquac 

If you liked one of the answers and it helped you resolve the issue, please click on the ‘Best Answer’ button. If you still have questions or doubts, please let us know so we can further assist.

Cheers!


Reply