Unable to access variable from variable set

Rolf Nyhus
Tera Guru

I've got a record Producer where one variable is named "myLoaction" (reference: cmn_location) and the value of this is to be used as a reference qualifier for another variable named "myAsset" (reference: alm_asset).

This is quite easily accomplished by using:

javascript:'location='+current.variables.myLocation.toString();

Unfortunately, it seems that this only works if both variables reside either directly on the RP or in the same variable set.

My challenge, is that I need "myLocation" to reside directly on the RP, whereas "myAsset" needs to reside in a variable set.
When I implement this, the reference qualifier no longer works, as it appears that the variables then operate in different scopes.

Top make this more complex, my variable set is of type multi-row. So for each row added to the VS, you should be able to select an asset that is qualified based on the location on the RP.

Anyone who has come across this challenge in the past and has some thoughts on how it can be resolved?

1 ACCEPTED SOLUTION

Rolf Nyhus
Tera Guru

Thanks for your efforts Tyler.

I ended up coding a work around. Basically what I did was have an onChange client script on the location variable in the RP which then writes the value to the logged in user's user record. Then in the MRVS I use an onLoad client script to set the value of it's location field based on the field on the user's user record.

Not very elegant, but it works.

View solution in original post

7 REPLIES 7

TylerTeter
Kilo Guru

Have you tried

current.variable_pool.myLocation.toString();

I know there are some known scoping issues with .variables only working within that variable set.

See also: https://community.servicenow.com/community?id=community_question&sys_id=94c68f65db1cdbc01dcaf3231f96...

Tried, but no dice

Rolf Nyhus
Tera Guru

Apparently what I'm trying to do is not supported. Anyone have any suggestion for a workaround?

 

https://docs.servicenow.com/bundle/london-it-service-management/page/product/service-catalog-management/concept/c_ServiceCatalogVariableSets.html

  • Variables that are not included in a multi-row variable set cannot be used in dependent reference qualifiers for variables in the multi-row variable set. Similarly, the variables included in the multi-row variable set cannot be used in dependent reference qualifiers for variables that are not in the multi-row variable set. For a reference qualifier, the current row is the one that is being edited.

I think I missed your previous note, about it being a multi-row update set. That does make it way different.

The only other way to mimic reference qualifiers that I know of is to either user like onChange client scripts to update the field values. I guess onDisplay business rules might be able to as well.

That being said, I'm not very familiar with Multi Row variable sets. From some reading, I've seen there are some limitations and special syntax you have to use to reference variables.

I'm assuming to do this kind of functionality you would need to dynamically find which row the user updated, and then dynamically update that row's variable filter.

https://community.servicenow.com/community?id=community_blog&sys_id=865b5aeddbc023c0feb1a851ca9619f9

https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/conce...