Fix Script:- Need to update date field on the record as date filed on the related record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2023 11:49 PM
Dear Team, I have requirement to update date filed on bulk records same as their related record and i need fix script for this, how ever i tried writing the script to update single record and it is working fine as expected.
I need a logic to achieve same functionality on bulk records , please find the below script and help..thank in advance !!
var gr = new GlideRecord('core_company');
gr.addQuery('sys_id','74638e021b720890e0e2fff7dc4bcb2d');
gr.query();
if(gr.next()){
var gr1 = new GlideRecord('sn_vdr_risk_asmt_assessment');
gr1.addQuery('sys_id','e433480387c6e51082390e59cebb3523');
gr1.query();
if(gr1.next()){
gr.u_rating_valid_to = gr1.risk_rating_valid_to;
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 12:50 AM
Thanks for the response this script is not working and also not showing any errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 10:53 PM
Hi @Chiranjeevi K ,
Two things needs to be changed in your script:
1: The query is for a single record
2: Instead of if use While
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 11:14 PM
Hi @Chiranjeevi K ,
You can try following the client script:
var tableName = "related_list_table_name"; // Replace "related_list_table_name" with the actual table name of the related list
var parentId = g_form.getUniqueValue(); // Get the sys_id of the parent record
// Query for the related list records
var gr = new GlideRecord('related_list_table_name');
gr.addQuery("parent", parentId);
gr.query();
// Update each related list record
while (gr.next()) {
// Set the field values on the related list record
gr.setValue("field_name", "new_value"); // Replace "field_name" with the actual field name you want to update, and "new_value" with the new value you want to set
gr.update();
}
If my answer has helped with your question, please mark my answer as an accepted solution and give a thumbs up.
Regards,
Aditya