
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 09:57 PM
Hello Community,
Looking for assistance to correct the background script below:
var grChi = new GlideRecord("ast_service");//child record
grChi.addQuery("");//query goes here
grChi.query();
while (grChil.next()) {
var grPar = new GlideRecord("ast_service");//parent record
grPar.addQuery('number',grPar.parent_contract);
grPar.query();
if (grPar.next()){
grPar.status = grChi.status;//update field on parent record
grPar.update();
}
}
Bonus question: How to convert script into a business rule?
Thank you in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 07:50 AM
@Desmo I have updated the background script code.
Old Code - added comments
var grChi = new GlideRecord("ast_service");//child record
grChi.addQuery("");//query goes here
grChi.query();
while (grChil.next()) { // this need to be updated as grChi.next as you have created grChi as object
var grPar = new GlideRecord("ast_service");//parent record
grPar.addQuery('number',grPar.parent_contract); // grPar.parent_contract you need to replace this with grChi.parent_contract to get the parent sys_id to get parent record as it's referece field use sys_id field
grPar.query();
if (grPar.next()){
grPar.status = grChi.status;//update field on parent record
grPar.update();
}
}
Corrected code
var grChi = new GlideRecord("ast_service");//child record
grChi.addQuery("");//query goes here
grChi.query();
while (grChi.next()) { // updated grChil to grChi
var grPar = new GlideRecord("ast_service");//parent record
grPar.addQuery('sys_id',grChi.parent_contract); // updated this line
grPar.query();
if (grPar.next()){
grPar.status = grChi.status;//update field on parent record
grPar.update();
}
}
Regards,
RJ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2023 10:10 PM - edited 08-18-2023 10:13 PM
Hi @Desmo ,
You need to create an after-business rule on the child table and try the below script.
var grPar = new GlideRecord("ast_service");//glide tablerecord
grPar.addQuery('sys_id',current.parent_contract);//get sysid of parent record
grPar.query();
if (grPar.next()){
grPar.status = current.status;//update field on parent record
grPar.update();
}
Regards,
RJ

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 01:29 PM
RJ,
Thanks for the business rule. Looking for assistance on the background script as well.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 07:50 AM
@Desmo I have updated the background script code.
Old Code - added comments
var grChi = new GlideRecord("ast_service");//child record
grChi.addQuery("");//query goes here
grChi.query();
while (grChil.next()) { // this need to be updated as grChi.next as you have created grChi as object
var grPar = new GlideRecord("ast_service");//parent record
grPar.addQuery('number',grPar.parent_contract); // grPar.parent_contract you need to replace this with grChi.parent_contract to get the parent sys_id to get parent record as it's referece field use sys_id field
grPar.query();
if (grPar.next()){
grPar.status = grChi.status;//update field on parent record
grPar.update();
}
}
Corrected code
var grChi = new GlideRecord("ast_service");//child record
grChi.addQuery("");//query goes here
grChi.query();
while (grChi.next()) { // updated grChil to grChi
var grPar = new GlideRecord("ast_service");//parent record
grPar.addQuery('sys_id',grChi.parent_contract); // updated this line
grPar.query();
if (grPar.next()){
grPar.status = grChi.status;//update field on parent record
grPar.update();
}
}
Regards,
RJ

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2023 04:01 PM
RJ,
Tested and confirmed working.
To quickly discern the manner of the question and provide a usable solution is of great ability--which only some people posses. Thank you.
Desmo