The CreatorCon Call for Content is officially open! Get started here.

Schedule Report - How to get a Reference Field to send an email notification?

Elton2
Tera Contributor

Hi everyone, how are you?!

 

Could you please give me a suggestion?! 

 

I have a Report needs to be sent to the Group Holder, but this Holder is in a Reference field called "Business Partner Department" (PRINT_1),

 

I checked and a colleague from this community suggested a script to me so a "Dot Walk" in the "Condition" section of the Schedule (PRINT_2), but unfortunately is not working to the Report:

 

var grCmdb = new GlideRecord('cmdb_ci_business_company');
grCmdb.query();
while (grCmdb.next()) {
    if (grCmdb.u_business_partner_department.u_holder) {
        gs.info(grCmdb.u_business_partner_department.u_holder);
    }

}

I just need to get the "Holder" of a reference field for the Report to be sent.

 

Could anyone please give me a tip or script suggestion?

Thanks for the support!

1 ACCEPTED SOLUTION

Shubham Singh
Mega Guru

Hi @Elton2 

 

Try to run it in background script and check the results. Use gs.info(grCmdb.getRowCount()) to check the number of records returned by query().

 

Use the below script:

var grCmdb = new GlideRecord('cmdb_ci_business_company');
grCmdb.addQuery(‘u_business_partner_department.u_holder’, ‘!=‘ , ‘’);
grCmdb.query();
gs.info(grCmdb.getRowCount()):
while (grCmdb.next()) {
gs.info(grCmdb.u_business_partner_department.u_holder);
}
 
This will be more efficient and time effective approach.
 
Validate if there is any field on cmdb_ci_business_company table with name as next. If yes, then use _next() in your while loop.
 
Thanks!
 
Please mark this response as correct and helpful ✔️👍

View solution in original post

2 REPLIES 2

Shubham Singh
Mega Guru

Hi @Elton2 

 

Try to run it in background script and check the results. Use gs.info(grCmdb.getRowCount()) to check the number of records returned by query().

 

Use the below script:

var grCmdb = new GlideRecord('cmdb_ci_business_company');
grCmdb.addQuery(‘u_business_partner_department.u_holder’, ‘!=‘ , ‘’);
grCmdb.query();
gs.info(grCmdb.getRowCount()):
while (grCmdb.next()) {
gs.info(grCmdb.u_business_partner_department.u_holder);
}
 
This will be more efficient and time effective approach.
 
Validate if there is any field on cmdb_ci_business_company table with name as next. If yes, then use _next() in your while loop.
 
Thanks!
 
Please mark this response as correct and helpful ✔️👍

Hi @Shubham Singh , how are you?!

Firstly, I would like to thank you for your support and professionalism, with your tip I managed to get the emails (print_1)!!!

So, answering your question: There is no field called "next" in the table.


The email that was picked up by Dot Walk must be entered in the field: address_list so that the Report is sent (print_2).

Because of this I thought about creating an empty array and/or an obj that will receive a userEmail (print_3) property, this way the obj or array would be inserted in the field: address_list (field where the user's email is located). (print_example)

 

var arr = [];
var grCmdb = new GlideRecord('cmdb_ci_business_company');
grCmdb.addQuery('u_business_partner_department.u_holder.email', '!=' , '');
grCmdb.query();
gs.info(grCmdb.getRowCount())
while (grCmdb.next()) {
    if(grCmdb.u_business_partner_department.u_holder.email);
gs.info(grCmdb.u_business_partner_department.u_holder.email);
 
//The email that was picked up by Dot Walk must be entered in the field: address_list
var obj = {};
obj.emailUser = grCmdb.u_business_partner_department.u_holder.email;
arr.push(obj);
}

 

But I'm not making any progress, could you please give me any suggestions?

Thanks again!