Getting value from a field in one table and having it show on another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 12:19 PM
Hello! I am still learning the ins and outs of ServiceNow and just had a question I was hoping could be answered.
- I have a string field on Table X called 'Return Reason'
- When the user inputs a value for that field and saves, I am trying to get the value shown onto Table Y
What is the best way to do this? Do I need to create a reference field on Table Y? Thank you for the time!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 12:35 PM
Hi @ndejoya,
Yes, you need to create a relationship between both table, so any record update can be updated in the other table matched record.
You can have either way to related both tables.
Table X has the field reference to Table Y
or
Table Y has the field reference to Table X
and write the BR on Table X ( becuase return reason is in this table ) and reach the related record from table x and update the desire field.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 12:40 PM
I see, so I will go ahead and create a reference field in Table Y. How would the BR look like? Haven't worked much with that yet. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 02:18 PM - edited 12-11-2024 02:19 PM
You would probably do an after update BR on table X. I'm assuming there is some relation between table X and Y that indicates to you which record of Y to update when X changes.
So you'll do something like this:
var table_y_record = current.table_y_record;
var gr = new GlideRecord('table_y');
gr.get('table_y_record');
gr.setValue('field', 'field_from_x');
gr.update();