cancel
Showing results for 
Search instead for 
Did you mean: 

pb7 setvalue for compute field not working

Former Member
0 Kudos

Friends,

string ls_user

ls_user=get_user();

messagebox("test",ls_user)   ====== this is working..

i tried with two different ways...both are not working..the dw_1 is in the crosstab report.

i want to send this user name either to the compute field or to the datawindow query directly in the where condition...

whichever is possible , pls provide me the solution.

dw_1.SetItem(1,'compute_1',ls_user)   ==== Not working

dw_1.object.compute_1.expression="'"+ls_user+"'"  === Not working..

thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

instead of the compute_1 use a static text

dw_1,modify ( 'st_user.text="' + ls_user + "' )

Former Member
0 Kudos

not working...

string ls_user

ls_user=get_user();

//messagebox("test",ls_user)

dw_1.modify ('t_1.text="' + ls_user + '"')

Former Member
0 Kudos

You don't need the quotes in the modify() statement, since ls_user is a string already. 

I prefer to build the complete string first:

string     ls_mod, ls_user

ls_user = get_user()

ls_mod = "t_1.text=" + ls_user

dw_1.modify(ls_mod)

Former Member
0 Kudos

you do need the quotes

Former Member
0 Kudos

Try messagebox (ls_user , dw_1.modify ('t_1.text="' + ls_user + '"'))

Former Member
0 Kudos

@lars....

your code is perfectly working fine with messagebox...but without message box its not working.

string ls_mod, ls_user

ls_user=get_user();

//messagebox (ls_user , dw_1.modify ('t_1.text="' + ls_user + '"')) === working fine

either of the below are not working..

ls_mod=dw_1.modify ('t_1.text="' + ls_user + '"') ==== not working

dw_1.modify ('t_1.text="' + ls_user + '"') ===== this also not working..

thanks

Former Member
0 Kudos

I am beginning to think there is something else at play here...

It appears that, whenever you throw a MessageBox you can see the user name on your datawindow (t_1)  but if you just set the value and don't "pause" it, you don't see it...

You could consider doing the modify in a posted event or even just adding post to the modify call:


dw_1.POST modify ('t_1.text="' + ls_user + '"') 


Or given you appear to be calling a global function get_user() you could have that hardcoded in the computed field expression from before.

Former Member
0 Kudos

you are great...working fine...still some more to go....when i try to pass this value in the query window...in the design ->datasource - > convert to syntax -> in the query's where condition...i included "student.mentor = :ls_user" its not working...i dont know where i am making mistake...

Former Member
0 Kudos

Don't confuse retrieval arguments used in your SQL Select statement with variables used in script. They have nothing to do with each other.

If your SELECT statement looks like this:

SELECT col1, col2

FROM STUDENT

WHERE MENTOR = :username

Then in script you could write:

string ls_user

ls_user = get_user()

dw_1.retrieve(ls_user)

Former Member
0 Kudos

You're absolutely right.  My example I looked at in my code was using a integer instead of a string.

Former Member
0 Kudos

@terry....thanks for your reply...but...i am getting an error...

"An argument used in the select is not defined"

when i go to Design -> Retrieval Arguments -> ls_user or username (which ever variable i used in the sql statement)

then its working..but each time while running the reports the user has to enter the username...thats why i want to hard code it...

thanks

Former Member
0 Kudos

The message 'An argument used in the select is not defined' means exactly that.  In my example, the argument is called 'username', so in the SQL painter under the menu Design, Retrieval arguments... you need to define that argument 'username' as a string.

Verify in your SELECT statement that you didn't make a typo.  The SQL painter should warn you about the unused argument when you try to exit the screen.

Former Member
0 Kudos

if i give define a variable name in the retrieval argument then when ever the user run this report..they have to enter the value...

i dont want to enter each time...

thats why iam getting the username from the login itself.

i am getting the login username in the variable ls_user and i am passing this variable in the sql painter query.

how can i get rid of this retrieval argument section...?

i want to pass the ls_user variable inside the sql's where condition of the sql painter.

Former Member
0 Kudos

Look at the example I gave earlier.  You pass the username as an argument to the retrieve() statement:

If your DataWindow cntains a SELECT statement like this:

SELECT col1, col2

FROM STUDENT

WHERE MENTOR = :username

Then in script you could write:

string ls_user

ls_user = get_user()

dw_1.retrieve(ls_user) <<<<<< Notice that you pass the value that in SQL will substitute the :username argument.

Former Member
0 Kudos

@terry...

thanks for your reply..what you said is correct and i followed ur code...but still is there any way to get rid of the argument window...

Still i am getting the argument window even if i write the same code which you suggested...

Former Member
0 Kudos

The argument window comes if powerbuilder tries to retrieve the data (e.g. on retrieve or insertrow) and no arguments are specified.

Your can avoid this if

  • you have no retrieval arguments 🙂
  • you call the retrieve or insert data yourself. This is only possible for the datawindow itself, DDDWs and reports in a composite dw. It is not possible for nested reports in other datawindow styles.
    If you have a child dw (dddw, report) and it does not contain a row powerbuilder will try to retrieve them!!!
  • you pass the retrieval argument from a value of the master to a nested report (use the arguments properties in general tab of the report object) but not to DDDWs. This value may be from a column or somewhat computed. Because the retrieval arguments of the master are always available you can also specify it.

Hope that helps you to find a way.

Former Member
0 Kudos

otherwise....is it possible to use this sqlca.LogID in my where condition...

because i am getting the user id from the sql server's login...

username=sqlca.logid

i tried

where mentor = :sqlca.LogID

or

where mentor = sqlca.LogID

both are not working...so if its possible pls correct me the mistake...

Former Member
0 Kudos

No, this is not possible this way.

As bind variables (e.g. :a ) you can only use arguments that you have specified in the dw sql painter.

Without bindung you can only use somewhat the database knows. SQLCA is a powerbuilder object, not a database one.

But the database knows the name of the connected user. The way to get it depends on your database. For MS SQL Server it should be SYSTEM_USER.

So you can write:

where mentor = SYSTEM_USER

So you don't need a retrieval argument.

Former Member
0 Kudos

Addition:

I don't know MS SQL Server but it may be, that the username in SYSTEM_USER is not in same case as in SQLCA.LogId. So it may be that you have to convert the mentor (e.g. to uppercase).

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi.

If you want to put a variable in the Where clause without an additional script to retrieve or any retrieval argument, you can create a database function to return the user name then call this function in the Where clause:

SELECT col1, col2

FROM STUDENT

WHERE MENTOR = get_user();

Regards,

Luiz

Former Member
0 Kudos

Try this:

ls_mod = 'compute_1.Expression=~"String(~''+ls_user+'~')~"'

dw_1.Modify(ls_mod)

hth,

Neil