Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Populate Record Producer variables based on another variable

shane_davis
Tera Expert

I'll make this short just as an example. I have a record producer which has the variables below.

Variable 1:
resolution_ticket_number
- Lookup from u_another_table using reference type which has a field with the same information as the field below in variable 2 and is also a string field.

Variable 2:
u_certain_number_2
- String field


When the user is filling out the record producer fields, I would like to populate variable 2 with the data in the table from variable 1.

6 REPLIES 6

shane_davis
Tera Expert

Anyone have any ideas on this? I've re-pasted the info below.

I've tried several different ways and searched the community and wiki, but still no results. Below is a pasted layout if you or someone else has time to review. Thank you!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

***Record Producer :***
Uses table u_lending_services_air. Sends data from record producer to that table.

Variables:
• resolution_desk_number ---- lookup reference from u_lending_services table
• cst_ticket_number --- string field
• customer_name --- string field
• account_loan_number --- string field

***Table 1: u_lending_services***

Variables:
• number --- string with default value "javascript:getNextObjNumberPadded();" which increments 1 number for each ticket
• u_cst_ticket_number --- string field
• u_customer_name --- string field
• u_loan_number --- string field

***GOAL: ***
1. User chooses a Resolution Desk Number from the lookup box that pulls from the u_lending_services table.
2. A script will run to pull the information FROM the u_lending_services table FOR the number chosen and populate that ticket's information in the record producer variable fields mentioned above.


shane_davis
Tera Expert

I figured it out!

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

if (!isLoading){
// make async server call to look at the Resolution Desk Number chosen from a lookup on the u_lending_services table
g_form.getReference('resolution_desk_number', handleCallback);
}
}
//Set the values in the record producer fields from the various field values on the ticket chosen above.
function handleCallback(result) {
g_form.setValue('account_loan_number', result.u_loan_number);
g_form.setValue('original_requestor', result.u_caller);
g_form.setValue('loan_amount', result.u_amount);
g_form.setValue('customer_name', result.u_customer_name);
g_form.setValue('cst_ticket_number', result.u_cst_ticket_number);
}