- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 05:44 AM
Hi experts, can we copy the below variables 'name: value' to the string field.
Like we do copy variables data to HR case description.
TIA
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 08:07 AM - edited ‎04-05-2024 08:08 AM
Hi @si21,
Hope you are doing well.
Proposed Solution
In order to achieve this task, I personally tried it on my Personal Developer Instance so that you can get the solution as soon as possible. For this, you just need to create an "On-Change Catalog Client Script" and configure it to get all the values of 3 fields that you mentioned in your ask or question and set the value of "String" Field with the help of the script mentioned below: -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getDisplayValue('requested_for'); // Replace requested_for with New manager name
var email = g_form.getDisplayValue('email'); // // Replace email with Location
var company = g_form.getDisplayValue('company'); // No need to change anything over here
if (name == '' || email == '') {
alert('Kindly fill above two fields first');
g_form.setValue('company', '');
} else {
var val = 'Name: ' + name + '\nEmail: ' + email + '\nCompany ' + company;
g_form.setValue('string', val);
}
}
For your reference, also attaching screenshots of the outputs that will give you better insights of how the script is working or the best thing will be to follow the solution and execute the scripts on your instance.
If Any Field is Missing: -
Alerting User to fill above two fields First.
Populate String Field if all the above 3 Fields are filled.
If you find this information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.
Thanks ‌‌:)
Aakash Garg
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 06:17 AM
Hi @si21
just create a onChange Catalog client script for your requirements:
Type: Onchange
Field : New manager name (Note: you need to create 3 different catalog client scripts for each field-->company, location)
var user = g_form.getValue('new_manager_name');
var company = g_form.getValue('company');
if (new_manager_name && company) {
// Fetching display values instead of sys_ids for user-friendly names
var userName = g_form.getDisplayBox('new_manager_name').value;
var companyName = g_form.getDisplayBox('company').value;
// Constructing the string
var combinedValue = 'new_manager_name' + userName + 'Company ' + companyName;
// Setting the constructed string to the target field
g_form.setValue('string', combinedValue);
}
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2024 08:07 AM - edited ‎04-05-2024 08:08 AM
Hi @si21,
Hope you are doing well.
Proposed Solution
In order to achieve this task, I personally tried it on my Personal Developer Instance so that you can get the solution as soon as possible. For this, you just need to create an "On-Change Catalog Client Script" and configure it to get all the values of 3 fields that you mentioned in your ask or question and set the value of "String" Field with the help of the script mentioned below: -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var name = g_form.getDisplayValue('requested_for'); // Replace requested_for with New manager name
var email = g_form.getDisplayValue('email'); // // Replace email with Location
var company = g_form.getDisplayValue('company'); // No need to change anything over here
if (name == '' || email == '') {
alert('Kindly fill above two fields first');
g_form.setValue('company', '');
} else {
var val = 'Name: ' + name + '\nEmail: ' + email + '\nCompany ' + company;
g_form.setValue('string', val);
}
}
For your reference, also attaching screenshots of the outputs that will give you better insights of how the script is working or the best thing will be to follow the solution and execute the scripts on your instance.
If Any Field is Missing: -
Alerting User to fill above two fields First.
Populate String Field if all the above 3 Fields are filled.
If you find this information/knowledge/solution helpful, please don't forget to mark my solution and reply as helpful and accepted.
Thanks ‌‌:)
Aakash Garg
ServiceNow Developer