How to take values from input fields and populate other fields

jkhovren
Tera Contributor

I need to take the values from 2 input variables on the catalog item to populate the detail description field.  How would i code that?  I know it would be a script I believe.   

 

So I have input1 variable and input2 variable defined and I want to populate the detail description field, description1 with both values with a space in between.  How would that look coded? And would I do it in a flow or in a script?

3 REPLIES 3

Danish Bhairag2
Tera Sage
Tera Sage

Hi @jkhovren ,

 

where is the description field present on catalog item form or on some record like Request or incident?

 

Thanks,

Danish

 

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @jkhovren 

https://www.servicenow.com/community/developer-forum/how-to-concatenate-two-variable-field-values-in...

LearnNGrowAtul_0-1706086632537.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

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

Rajdeep Ganguly
Mega Guru


You can achieve this by using a Catalog Client Script. Here are the steps:

1. Navigate to Service Catalog > Catalog Definitions > Maintain Items.
2. Open the catalog item you want to modify.
3. Under the related links, click on "Client Scripts".
4. Click on "New" to create a new client script.
5. Fill in the fields:
- Name: Give a meaningful name to your script.
- Type: Select "OnLoad".
- Catalog Item: Select the catalog item you are modifying.
6. In the "Script" field, write the following JavaScript code:

javascript
function onLoad() {
//Get the values of the two variables
var input1 = g_form.getValue('input1');
var input2 = g_form.getValue('input2');

//Concatenate the values with a space in between
var description1 = input1 + " " + input2;

//Set the value of the detail description field
g_form.setValue('description1', description1);
}

7. Click on "Submit" to save the client script.

This script will run every time the catalog item is loaded, and it will populate the 'description1' field with the values of 'input1' and 'input2' variables.

Please replace 'input1', 'input2', and 'description1' with the actual names of your variables and field.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER