- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2020 05:49 PM
I did some research and thought I could accomplish what I need, but it doesn't work.
I would like to take some free-text input from a variable, and copy it to another variable field (which I would set as read-only via UI policy).
Is that possible? Let me add that I'm fairly new at writing these.
Below is my script which doesn't work like I need it to.
Catalog Client script onChange for the variable that user will fill "fill_this".
If he changes his mind / populates a new value into the first field, the 2nd field will clear and re-populate with his new text.
My 2 variables are
fill_this (where user enters text)
populate_that (where I also want to auto-populate the same text)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == "") {
return;
}
if(newValue != oldvalue) {
var data = g_form.getDisplayValue('fill_this');
g_form.setValue('populate_that', data);
}
}
And if I may add another scenario (different use-case) I would like to be able to do the same with a reference table.
User selects a service from a Reference variable; I want the same service to populate in another variable field on the form (read-only field per ui policy). If he changes his mind, the 2nd value is also cleared and re-populated.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2020 07:32 AM
Hi,
What is the business requirement here as both the variables will hold same value? is this valid business requirement
if both are string type then below should work
the below would be onchange catalog client script on the variable fill_this
since the 2nd variable would be auto-populated set it read-only in same script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
g_form.setReadOnly('populate_that', true); // set to read-only on load
return;
}
// script to set value to 2nd variable
if(newValue == "")
g_form.clearValue('populate_that');
if(newValue != oldvalue) {
g_form.setValue('populate_that', newValue);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 01:04 PM
Hi All. Mike's solution worked for me. What I noticed is in Tami's script, make sure to capitalize the V in "oldValue".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2020 07:32 AM
Hi,
What is the business requirement here as both the variables will hold same value? is this valid business requirement
if both are string type then below should work
the below would be onchange catalog client script on the variable fill_this
since the 2nd variable would be auto-populated set it read-only in same script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
g_form.setReadOnly('populate_that', true); // set to read-only on load
return;
}
// script to set value to 2nd variable
if(newValue == "")
g_form.clearValue('populate_that');
if(newValue != oldvalue) {
g_form.setValue('populate_that', newValue);
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 05:02 AM
thank you! It worked when making sure oldValue is properly spelled as mentioned below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 01:04 PM
Hi All. Mike's solution worked for me. What I noticed is in Tami's script, make sure to capitalize the V in "oldValue".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2022 05:03 AM
Thanks so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2020 09:30 AM
Business case:
I have a field on a catalog item, which user fills what they want a new Service to be named.
In another part of the form, the same Service name is needed when the fulfiller is creating Server/Cluster (as the Owning service).
Of course I could reference there "Make it the same as xx field" but was trying to populate it the same by script.
I am a catalog editor but not a sys admin, so I will inquire within to find an answer.
Thanks for your help; but even the final context did not work for me.