The CreatorCon Call for Content is officially open! Get started here.

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

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.

You're welcome, glad you got it finally working sir!

I'd be slightly intrigued to see some of that code.

Yeah doesn't sound the most elegant, but if it works, then it works. I'm curious if it's possible to use g_scratchpad in this situation. I'm not sure if the MRVS scope restricts it.

Hi Tyler,

Finally back from an extended x-mas break. As mentioned it just did a crude implementation, I'm sure there are ways to improve on this (code included).

 

onChange Client Script on RP:
=============================
function onChange(control, oldValue, newValue, isLoading) {
 if (isLoading || newValue == '') {
  return;
 }
 
 var ga = new GlideAjax('setMyLocation');
 ga.addParam('sysparm_name', 'setAddressOnUser');
 ga.addParam('sysparm_usersysid', g_user.userID);
 ga.addParam('sysparm_address', g_form.getValue("lokasjon"));
 ga.getXML(callback);
 
 function callback(response){
  return true;
 }
}


Script Include:
===============
var setMyLocation = Class.create();
setMyLocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
 setAddressOnUser: function(){
  var thisAddress = this.getParameter('sysparm_address');
  var thisUser = this.getParameter('sysparm_usersysid');
  
  var gr = new GlideRecord("sys_user");
  gr.get(thisUser);
  gr.location = thisAddress;
  gr.update();
  return true;
 }
});


onLoad Client Script on MRVS:
=============================
function onLoad() {
 //Type appropriate comment here, and begin script below
 var gr = new GlideRecord("sys_user");
 gr.addQuery("sys_id", g_user.userID);
 gr.query(setUser);
 
 function setUser(gr){
  if(gr.next()){
   g_form.setValue("myLocation",gr.location);
  }
 }
}