Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
somenathroy
Creator III
Creator III

Try to get OSUser() into Extension Object

Dear All,

My objective is to use the logged in user name into a QV Extension. For that I have declared a variable through Variable Overview dialogue as  : vLoggedinUser =OSUser()

Have checked that the value of the variable showing correctly in a standard QV text object as <domainname>\<username>.

Now want to take this value in an extension object, so have written the following code block in Script.js file :

/*setting VariABLES*/

var _this = this;

var vUser ;

  _this.StaticPros = {};

  _this.StaticPros .UserName = eval('_this.Layout.Text0.text');

  var qvDoc = Qv.GetCurrentDocument();

                qvDoc.GetAllVariables(function (vars) {

                    if (vars != null) {

                        for (var i = 0; i < vars.length; i++) {

                            var obj = vars;

                            if ((obj.isreserved == "false") && (obj.isconfig == "false")) {

                                if (obj.name.toLowerCase() == _this.StaticPros .UserName.toLowerCase()) {

                                    vUser = obj.value.toString();  //return variable definition text

                                                                               //[i.e =OSUser() , should return <domainname>\<username>]

                                  //vUser = obj.name.toString();   //return the name of the variable [i.e vLoggedinUser ] correctly

                                }

                            }

                        }

                    }

                });

vUser = obj.name.toString();  returns the name of the variable [i.e vLoggedinUser ] which is perfect.

But, vUser = obj.value.toString(); returns variable definition text [i.e =OSUser() ] which is wrong. It should return <domainname>\<username>].

Can anyone point me if I am missing anything or any better idea ? Would appreciate your help.

Regards,

Som

2 Replies
somenathroy
Creator III
Creator III
Author

Dear All,

Has anyone faced this problem ?

Regards,

som

ericpark
Partner - Contributor
Partner - Contributor

in Definition.xml add:

<Text Label="OSUSER" Type="text" Initial="" Expression="=OSUser()"/>

then in the javascript reference it by:

_this.Layout.Text0.text