Populating Field in Service Portal Based on Previous Selection

jmiskey
Kilo Sage

So, I am creating a Form for our Service Portal.   I had to create a few Custom Tables for this endeavor.

One such table is called "IT Portfolio" (u_it_portfolio).   It has a few field, the most important being:

u_it_portfolio

u_it_portfolio_mgr

The u_it_portfolio field is simply a String field (and this is the Display field).

The u_it_portfolio_mgr field is a Reference field back to sys_user.

So, basically, this table shows each IT Portfolio and who the manager is of each one.

On the Service Portal, we created a variable named itPortfolio, which is a reference field back to the u_it_portfolio table.

There is another read-only variable on the Service Portal named itPortfolioMgr.

The intention is that when the user selects a value from the itPortfolio question, based on that selection, it will populate the itPortfolioMgr variable with the corresponding value from the u_it_portfolio_mgr field in the u_it_portfolio table.

I know that this will be a Catalog Client Script which runs on the onChange event of the itPortfolio variable.   But I am having issues figuring out the correct syntax to return a value from the same record in the reference table (but returning a different field from that record).

I have a feeling that this is probably an easy one, and I am going to kick myself for not being able to come up with it myself once I see the solution!

Thanks

1 ACCEPTED SOLUTION

I figured it out!   Working in conjunction with the Client Script code I posted earlier that is returning a sys_id, I just need to make the variable a Reference variable, and it will return the User's name.



I had tried this earlier, but I was trying to make it a Reference variable to my u_it_portfolio table.   But I since discovered that the sys_id that it was returning was actually from the sys_user table.   When I changed it to be a reference to the sys_user table, it worked!


View solution in original post

7 REPLIES 7

jmiskey
Kilo Sage

In case it is a little confusing, let me show a simple example:


   


u_it_portfoliou_it_portfolio_mgr
Customer ServiceJohn Smith
Document ServicesJane Doe
Help DeskBob White
MembershipTammy Jones
SalesJohn Smith


So above is an example of my IT Portfolio table.   Note that the second field is a reference field to the sys_user table.


So, on the Service Portal, I want them to be able to select the IT Portfolio from a drop-down box (from first column above), and then it should populate another read-only field on my Service Portal form with the corresponding manager.



For example, if I selected "Help Desk", it should automatically populate my Manager field on my Service Portal form with "Bob White".



Thanks


OK, it appears I am getting really close.   After a bunch of research, and playing around, I came up with this script:



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


          return;


  }



var itPortRec = g_form.getReference('itPortfolio',itPortMgr);



function itPortMgr(itPortRec) {


g_form.setValue('itPortfolioMgr',itPortRec.u_it_portfolio_mgr);


}



}



The issue is that this seems to return a sys_id in my Single Line Text variable, instead of the value.


Note that the value I want to display is NOT the Display field (u_it_portfolio is set to be the Display field on the table).


I want to show the corresponding u_it_portfolio_mgr field (which itself is a reference field to the sys_user table).


In the "IT Portfolio" make the u_it_portfolio_mgr as display field "true"



Note- there should be only one Display field true.




find_real_file.png



Hit like or mark as correct answer



Thanks


Sudhir


In the "IT Portfolio" make the u_it_portfolio_mgr as display field "true"



Note- there should be only one Display field true.


That won't work.   The other field, the u_it_portfolio field, NEEDS to be the Display field, as that is the field that needs to be displayed for the previous Reference Variable (the one that this Client Script is being attached to).