Service Catalog - Passing data between catalog client scripts and Variable reference qualifier

JPing
Tera Expert

Hello, 

 

We have a catalog request where someone can request services for one or many users. The catch is that all users have to have the same manager. 

 

I have a multi Row variable set that has 1 variable that reference the sys_user table "user". Goal: for the first row all the users should be selectable.  When the user makes the second selection, the sys_user table should filter to match only users with the same manager of the first row. 

 

Here is what I have done: 

We create a second variable in the MRVs called "active manger". We use an onload Catalog Client script to set the "active manager" by passing in the MRV as a whole using 

g_service_catalog.parent.getValue("<mrv set name>"). If the MRV is blank meaning it is the first record, then the active manager will be blank. If there is data in the MRV, we look at the first index of the MRV, look up the user reference and then dot walk to the user.manager field and set that as the active manager. 
 
In the "user" field we have a reference qualifier that calls a script include and passes the active manager value (current.varaibles.active_manager) and then it returns a list of sys_ids of all the user that share the same manager.  If active_manager is blank it will not add a filter and thus return all users. 
Ex: javascript&colon; new <script include>().getUsers(current.variables.active_manager);
 
This actually work perfectly. the problem is that the active manager column should not be shown in the MRVs table in the parent form. So I need to either hide the column on the table, which from old post says you can't or I need a new mechanism for passing the results of the onload script to the reference qualifier where I'm not creating a new variable.
 

Simplified Question: 

Is there a mechanism that I can save the results of an onLoad client script and then access it in a ref Qualifier on a variable? 

 

Note something we could not figure out, is we could not pass the MRVs as a whole into the Reference qualifier of the user variable: 

Ex: javascript&colon; new <script include>().getUsers(g_service_catalog.parent.getValue("<mrv set name>")); 

g_service_catalog was undefined

 

I hope I am as clear as I can be. 

 

Thanks in advance. 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Good work.  Unfortunately you've run up against a few current limitations in the design of the MRVS.  A few years/releases ago g_service_catalog was introduced as a way to get values from the parent form to use in the MRVS, but the reference qualifier remains outside of this due to the current.variables notation to pass a variable value to a Script Include.  Also as you have discovered, hiding the MRVS variable through any means only hides it in the add/edit dialog window.

Something to try in your scenario that may just work is to set the value of the user variable in your onLoad script to the manager of the user from row 1, then use that variable in the reference qualifier.  It will either not work due to the timing - the reference qualifier runs before the onLoad finishes, or maybe the list will be filtered correctly, but the manager's name still populated - even though that user wouldn't be one of the valid choices, or maybe the list will be filtered and the value cleared? 

View solution in original post

3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Good work.  Unfortunately you've run up against a few current limitations in the design of the MRVS.  A few years/releases ago g_service_catalog was introduced as a way to get values from the parent form to use in the MRVS, but the reference qualifier remains outside of this due to the current.variables notation to pass a variable value to a Script Include.  Also as you have discovered, hiding the MRVS variable through any means only hides it in the add/edit dialog window.

Something to try in your scenario that may just work is to set the value of the user variable in your onLoad script to the manager of the user from row 1, then use that variable in the reference qualifier.  It will either not work due to the timing - the reference qualifier runs before the onLoad finishes, or maybe the list will be filtered correctly, but the manager's name still populated - even though that user wouldn't be one of the valid choices, or maybe the list will be filtered and the value cleared? 

I took some time to read this after I found my own workaround with session, but this works. The down side is that I have to show a manager field in the MRVs tables but I was doing that anyways. At least now I don't have to have an extra column for active manager. 

 

After reading you suggestion, I reflected and this is just so clever. What would make this even better if Catalog variables had a dependent field like this do for platform variables. Then you can just set the manager field with an onload and then an auto filter would be applied to the user field. 

 

Thanks

 

JPing
Tera Expert

Just an update to anyone that reads this. Another way to pass data from an onload script to a reference qualifier on a variable is to use the Session.

In the Script include:
...
var session = gs.getSession();
session.putClientData("active_manager", "bob");
...



in the Ref Qaulifier 
session.getClientData('active_manager');

 

In the onload script you can make an AJAX call to a script include to set the value in the session and then in the reference qualifier you can read the session. Obvious down side is that if you have two entities that interact with the same session variable at the same time, they will overwrite the session value in certain timings.