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 01:00 AM
Thanks for the response but, the script not working for my requirement could you please help and review
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 12:06 AM
Hello Chiranjeevi.
If this works for single record as expected then it should also work for multiple (provided you are iterating through using while loop instead of if).
I would like to validate your multiple record / bulk record update script to help you better.
But if you are confident enough about bulk record updates then
you can try adding 'gr.setWorkflow(false);' before your last gr.update();. PS: setworkflow will stop execution of BRs that happens after this update but can be useful when you are not expecting anything else (like notifications) to be triggered after this update as part of fix script.
If you dont want to use setWorkflow(false) because of some reasons then share your script along with type of field 'u_rating_valid_to ' and 'risk_rating_valid_to'
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 01:01 AM
It is working when I am comparing the parent and related record sys_id but for bulk record updates not working need help !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 01:41 AM
Can you please share your script for bulk update of these fields?
have you tried adding setWorkflow(false) as well before updating?
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 12:08 AM
Hi @Chiranjeevi K ,
To update the date field on bulk records, you will need to use a loop to iterate over each record that needs to be updated. Here is an example of how you could modify the script to update the "u_rating_valid_to" field on all "core_company" records that have a related "sn_vdr_risk_asmt_assessment" record with a matching sys_id:
var gr = new GlideRecord('core_company');
gr.query();
while (gr.next()) {
var gr1 = new GlideRecord('sn_vdr_risk_asmt_assessment');
gr1.addQuery('sys_id', gr.sys_id);
gr1.query();
if (gr1.next()) {
gr.u_rating_valid_to = gr1.risk_rating_valid_to;
gr.update();
}
}
Note that this script assumes that the "sys_id" field on the "core_company" table corresponds to the "sys_id" field on the "sn_vdr_risk_asmt_assessment" table, and that there is a one-to-one relationship between these two tables. If this is not the case, you will need to modify the script accordingly.
Shravan
Please mark this as helpful and correct answer, if this helps you