Change a field in another table with BR when another field is updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 06:46 AM
Hello.
I have a field named u_maanedspris in the table u_leiepris
when i edit this field i want the field (u_gjelende_leiepris) in the table named u_leiekategori to change to the same value.
This is the script i have so far for my BR and its not working. The BR is set to the u_leiepris table:
(function executeRule(current, previous /*null when async*/ ) {
var a = current.u_maanedspris;
var grL = new GlideRecord('u_leiekategori');
current.grL.u_gjeldene_leiepris = a;
current.update();
})(current, previous);
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 06:55 AM
Hi,
Can you share if these two tables are linked with each other or not? If yes then can you share how it is linked to each other any common field which is linking them?
For example I have done this for two tables Incident and Incident Task which has a common field as Incident so when there is an Update on Incident task same gets updated in Incident as well using below script.
Please use and modify accordingly:
Write a After Update BR on Child Table and then use the script as below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('Parent table Name');
gr.addQuery('sys_id',current.FIELD Connecting Both table here);
gr.query();
if(gr.next()){
gr.PARENT_FIELD_NAME = current.CHILD_FIELD_NAME;
gr.update();
}
})(current, previous);
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 07:15 AM
Hello.
Im not quite sure how i can see if they are related, but im quite sure they are not. So how do i change this if the fields are not related
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2022 08:09 AM
You need to make them related so that when you update in one table you can identify and u[date the other respective record, else I don't think you will be able to do it unless you relate them.
If it is not related and you want to do that then create a Reference Type of field on Child Table and reference it to your Parent table , this way you can link your both tables and use the script above.
I have given a similar answer in below thread, please refer the same:
https://community.servicenow.com/community?id=community_question&sys_id=6e75e096db748510679499ead39619b4
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke