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

Set Reference field 'default value' based on existing Reference field.

Wesley Breshear
Tera Expert

Hello,

On the Business Service form, we have added the 2 Portfolio reference fields that reference the 'Product Portfolio' table. One called 'Product Portfolio' (u_prdct_portfolio) and one 'Software Development Organization' (u_sd_portfolio).  I am trying to pull the "Manager" field/value from each portfolio record to a reference field called 'PP Manager' and 'SD Manager' on the same Business Service form.   I was able to dot.walk the field from the Portfolio Table but then I can only have one manager field on the form.

I have seen some articles and even thought @Chuck Tomasi had created a YouTube pulling values from an existing reference field because reference fields bring all the data values related to it to the form but I can't track it down.  I know it can be done with GlideAjax but trying to keep to a simpler solution. I have tried the following to the Dictionary Entry's 'Default Value' field but no success.

javascript:u_prdct_portfolio.portfolio_manager;

javascript:u_prdct_portfolio.portfolio_manager.toString();

javascript:u_prdct_portfolio.portfolio_manager.getDisplayValue();

javascript:new u_prdct_portfolio.portfolio_manager;

javascript:new u_prdct_portfolio.portfolio_manager.toString();

javascript:new u_prdct_portfolio.portfolio_manager.getDisplayValue();

 

So now I am trying this article's onChange Client Script but I am still missing something. https://community.servicenow.com/community?id=community_question&sys_id=05638725dbd8dbc01dcaf3231f96...

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	var ppm = g_form.getReference('u_prdct_portfolio', manager);
}

function manager(pm) {
	g_form.setValue('u_prdct_portfolio.manager', ppm.portfolio_manager);
}

 

Thank you for your help,

-Wesley

1 ACCEPTED SOLUTION

Okay.

So in your onchange client script function, there is an error in the parameters passing. Try this code

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  var ppm = g_form.getReference('u_prdct_portfolio', manager);
  function manager(ppm) {
    g_form.setValue('u_prdct_portfolio.manager', ppm.portfolio_manager); //cross verify the field name once if this is correct?
  }
}

Similarly, write onchange for the other field as well.

Mark the comment as a correct answer and also helpful once worked.

View solution in original post

4 REPLIES 4

asifnoor
Kilo Patron

Hi,

If you want to have more than 1 manager shown, then you need to create those fields as reference and then under Reference specification, select advanced qualifier and call a script include which returns the comma separated sys_ids of all portfolio managers.

Mark the comment as a correct answer if this answers your question.

Hello Asifnoor,

Nope, not more than 1 manager.  One manager for 'Product Portfolio' and one manager for 'Software Development Organization' would auto-populate them manager for that selected porfolio.  Both managers would be pulled from the same Product Portfolio Out-of-the-box table.  So user would select Product Portfolio and the manager would auto-populate and then when the user selects the Software Development Organization the manager for that portfolio would auto-populate to its respective manager field.

Hope that makes sense.

-Wesley

Okay.

So in your onchange client script function, there is an error in the parameters passing. Try this code

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
  var ppm = g_form.getReference('u_prdct_portfolio', manager);
  function manager(ppm) {
    g_form.setValue('u_prdct_portfolio.manager', ppm.portfolio_manager); //cross verify the field name once if this is correct?
  }
}

Similarly, write onchange for the other field as well.

Mark the comment as a correct answer and also helpful once worked.

Wesley Breshear
Tera Expert

Hi Asifnor,

I found out the issue.  My client script was on [cmdb_ci_service_discovered] table vs. [cmdb_ci_service] and I was working with a Business Service record that hadn't been discovered yet.  Once I created the client script on the [cmdb_ci_service] table everything worked great. Small ServiceNow glitch (migration issue) you have to pay attention if the Business Service has been mapped/discovered yet.  If so, you get redirected to a different table.

Thanks your help.

-Wesley