Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

How to pass account value to record producer when clicked on Create Case using case type selector?

Devangi S
Tera Contributor

We have Create Case button in Account table. We allow user to create case from Account record by clicking on Create Case button which displays the Case Type Selector page that displays the record producers of all case types. When user selects any one record producer that has the account variable, it must auto populate the account from which Create Case was clicked. But it's not working. When we dont have any record producer and directly displays the sn_customerservice_case.do, it displays the account. How can we auto populate the account using record producer?

8 REPLIES 8

Tanushree Maiti
Kilo Patron

Hi @Devangi S 

 

1) When clicking UI action , you can pass the account using Sys_param

 

Sample code :

UI action to call the record producer

action.setRedirectURL('/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=[sys_id of record producer]&sysparm_recordsysid=' + current.getUniqueValue());

 

2) In Record producer, create a onload client script to capture the account value and set it to record producer account variable.

 

Sample code : //change as per your requirement

function onLoad() { 

var url = new URLSearchParams(this.location.href);

var recordSysId = url.get('sysparm_recordsysid');

g_form.setValue('parent', recordSysId);

}

 

Ref: https://incident.do/2024/08/27/servicenow-record-producer-client-scripts-populate-variables-from-url...

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

vaishali231
Kilo Sage

hey @Devangi S 

To auto-populate Account in a Record Producer when clicking Create Case from the Account form, you must explicitly pass and map the context. Record Producers do not automatically inherit URL parameters like standard forms do.

 

 Reason

Opening sn_customerservice_case.do directly works because the platform reads:

sysparm_account=<sys_id>

Record Producers do not auto-bind URL parameters to variables

You must manually handle:

URL - Variable - Target field

 

Approach

1. Update “Create Case” UI Action

Pass the Account sys_id in the URL:

var url = '/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=<record_producer_sys_id>' +

         '&sysparm_account=' + current.sys_id;

action.setRedirectURL(url);

 

 If using a Case Type Selector page, ensure it also forwards:

sysparm_account=<account_sys_id>

when redirecting to the selected Record Producer.

 

2. Add Catalog Client Script (onLoad)

This ensures the Account is populated on the form:

function onLoad() {
   var accountId = g_request.getParameter('sysparm_account');
   if (accountId) {
       g_form.setValue('account', accountId);
   }
}
 Use g_request.getParameter() (reliable for Record Producers)


3. Map Variable to Case Field (Record Producer Script)

(function executeProducerScript(current, producer) {
   if (producer.account) {
       current.account = producer.account;
   }

})(current, producer);

**********************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

Regards

Vaishali Singh





 



Hi @vaishali231 ,

 

We are using declarative action form button not UI action. Yes we have declarative action using case type selector page that loads the records producers and once user selects the record producer, it load the record producer in the workspace. Is there any way to pass account to case type selector and then to selected record producer?

Devangi S
Tera Contributor

Hi @Tanushree Maiti ,

 

Thanks for the quick response. 

We cannot use this approach since the button is the declarative action as shown below.  Also there are multiple record producers associated with each case type. We cannot pass static sys ids of the record producers.

DevangiS_0-1776677583419.png