Reference variable copying
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 11:13 AM
How can we copy reference variable to other reference variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 09:27 PM
Hi @vsxacvxjhsgvxck ,
Please refer to this solution: https://www.servicenow.com/community/developer-forum/how-to-copy-one-reference-field-value-into-anot...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2023 09:48 PM
@vsxacvxjhsgvxck The solution depends on when & from where you wanted to copy the reference variable.
If you are referring to a service catalog/record producer which has 2 reference variables (requested_by & requested_for) to the sys_user table and you wanted to copy the value selected in one reference field to another.
Please create a client script of type "onChange" for the variable name "requested_by" and add the below script. Please adjust the field names according to your requirement.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.setValue('requested_for',newValue)
//Type appropriate comment here, and begin script below
}
Please mark the appropriate response as correct answer and helpful.
Thanks!!