on 01-10-2015 6:45 AM
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
instead of the compute_1 use a static text
dw_1,modify ( 'st_user.text="' + ls_user + "' )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
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.
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)
@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
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.
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.
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.
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
Hope that helps you to find a way.
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...
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this:
ls_mod = 'compute_1.Expression=~"String(~''+ls_user+'~')~"'
dw_1.Modify(ls_mod)
hth,
Neil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.