parentView reference from Global Ready Function

Hello Dundas,

What is the recommended way of referencing the parent view from a global function? By global function i mean that I have a function written inside of the ready script like this:

window.functionName() {
//get parent view to reference parameters
}

I have always seen it references as this.parentview, and while trying to pass this.parentView into the function I am still getting ‘parentView is undefined’. Tips appreciated!

Thanks

Hi Ryan,

Since you are in the ready action of the dashboard, you can simply use the keyword “this” instead of passing the “this.parentView” from the adapter calling this function.
For instance, if you were to load a view parameter in the ready action you would simply use:

this.control.getViewParameterByName("viewParameter1");
and you will get your resultant view parameter:


I hope this helps.

Does this work for you when you put it inside of a function? It does not for me.

If I just place your code in the ready script then it works great and honestly I was already there. If I put that code inside of a function inside of a ready script then I receive the error “this is undefined”.

I don’t care where it goes but I don’t want redundant code spread out through all of my controls and would like to just have it in one location.

Thanks

Hi Ryan,

In your case, you can create a variable and assign it “this” and then use this variable in your functions, something like the below script:

var _this = this;
window.test = function(){
	var a = _this.control.getViewParameterByName("viewParameter2");
	console.log(a);
}

Can you please give this a try and let me know if this helps?

1 Like

Working, thank you!!