Getting values from a parameter in an event

matthew_hughes
Kilo Sage

I've got the following scheduled job that collects information about business applications and potential users, whose end date is approaching:

//User is an Application Service Steward for an Application Service where Status is not Disposed, and user's Manager is Active
var grOwnership = new GlideRecord('cmdb_ci_business_app');
grOwnership.addEncodedQuery('u_business_owner.active=true^u_business_owner.u_end_dateRELATIVELT@dayofweek@ahead@30^NQu_cmdb_data_steward.active=true^u_cmdb_data_steward.u_end_dateRELATIVELT@dayofweek@ahead@30^NQu_custodian.active=true^u_custodian.u_end_dateRELATIVELT@dayofweek@ahead@30');
grOwnership.query();
ownersLoop = [];
while (grOwnership.next()) {
    //Get the value of the Divisional Application Owner and convert it to a string
    var divisionalApplicationOwner = grOwnership.u_business_owner + '';
    //If there is already an existing entry, remove the duplicate entry
    if (ownersLoop.indexOf(divisionalApplicationOwner) == -1) {
        //Add the single entry to the ownersLoop  
        ownersLoop.push(divisionalApplicationOwner);
        gs.eventQueue('lbg.notify.reassign_new_owner_DAO', grOwnership, grOwnership.u_business_owner.manager.toString(), divisionalApplicationOwner);
    }

    //Get the value of the Business Application Steward and convert it to a string
    var businessApplicationSteward = grOwnership.u_cmdb_data_steward + '';
    //If there is already an existing entry, remove the duplicate entry
    if (ownersLoop.indexOf(businessApplicationSteward) == -1) {
        //Add the single entry to the ownersLoop
        ownersLoop.push(businessApplicationSteward);
        gs.eventQueue('lbg.notify.reassign_new_owner_BAS', grOwnership, grOwnership.u_cmdb_data_steward.manager.toString(), businessApplicationSteward);
    }
   
    //Get the value of the Technical Application Owner and convert it to a string
    var technicalApplicationOwner = grOwnership.u_custodian + '';
    //If there is already an existing entry, remove the duplicate entry
    if (ownersLoop.indexOf(technicalApplicationOwner) == -1) {
        //Add the single entry to the ownersLoop
        ownersLoop.push(technicalApplicationOwner);
        gs.eventQueue('lbg.notify.reassign_new_owner_TAO', grOwnership, grOwnership.u_custodian.manager.toString(), technicalApplicationOwner);
    }
}
 
I'm wanting to obtain the end date and name fields within the second parameter into an email:
 
matthew_hughes_3-1704718627939.png

 

However, when I preview my notification, I'm getting sys IDs instead of the values I need:

 

matthew_hughes_4-1704718712593.png

 

I was wondering if somebody could explain how I get the required values so that they are displayed correctly in my email.

3 REPLIES 3

Harsh_Deep
Giga Sage
Giga Sage

Hello @matthew_hughes 

 

Please make below changes-

 

 

var grOwnership = new GlideRecord('cmdb_ci_business_app');
grOwnership.addEncodedQuery('u_business_owner.active=true^u_business_owner.u_end_dateRELATIVELT@dayofweek@ahead@30^NQu_cmdb_data_steward.active=true^u_cmdb_data_steward.u_end_dateRELATIVELT@dayofweek@ahead@30^NQu_custodian.active=true^u_custodian.u_end_dateRELATIVELT@dayofweek@ahead@30');
grOwnership.query();
ownersLoop = [];
while (grOwnership.next()) {
//Get the value of the Divisional Application Owner and convert it to a string
var divisionalApplicationOwner = grOwnership.u_business_owner + '';
//If there is already an existing entry, remove the duplicate entry
if (ownersLoop.indexOf(divisionalApplicationOwner) == -1) {
//Add the single entry to the ownersLoop
ownersLoop.push(divisionalApplicationOwner);
gs.eventQueue('lbg.notify.reassign_new_owner_DAO', grOwnership, grOwnership.u_business_owner.manager.toString(), grOwnership.u_business_owner.getDisplayValue());
}

//Get the value of the Business Application Steward and convert it to a string
var businessApplicationSteward = grOwnership.u_cmdb_data_steward + '';
//If there is already an existing entry, remove the duplicate entry
if (ownersLoop.indexOf(businessApplicationSteward) == -1) {
//Add the single entry to the ownersLoop
ownersLoop.push(businessApplicationSteward);
gs.eventQueue('lbg.notify.reassign_new_owner_BAS', grOwnership, grOwnership.u_cmdb_data_steward.manager.toString(), grOwnership.u_cmdb_data_steward.getDisplayValue());
}

//Get the value of the Technical Application Owner and convert it to a string
var technicalApplicationOwner = grOwnership.u_custodian + '';
//If there is already an existing entry, remove the duplicate entry
if (ownersLoop.indexOf(technicalApplicationOwner) == -1) {
//Add the single entry to the ownersLoop
ownersLoop.push(technicalApplicationOwner);
gs.eventQueue('lbg.notify.reassign_new_owner_TAO', grOwnership, grOwnership.u_custodian.manager.toString(), grOwnership.u_custodian.getDisplayValue());
}
}

 

 

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Ankur Bawiskar
Tera Patron
Tera Patron

@matthew_hughes 

u_business_owner field on cmdb_ci_business_app table is reference to user and you are pushing the sysId

Do this change in script for 3 lines and it will work

//User is an Application Service Steward for an Application Service where Status is not Disposed, and user's Manager is Active
var grOwnership = new GlideRecord('cmdb_ci_business_app');
grOwnership.addEncodedQuery('u_business_owner.active=true^u_business_owner.u_end_dateRELATIVELT@dayofweek@ahead@30^NQu_cmdb_data_steward.active=true^u_cmdb_data_steward.u_end_dateRELATIVELT@dayofweek@ahead@30^NQu_custodian.active=true^u_custodian.u_end_dateRELATIVELT@dayofweek@ahead@30');
grOwnership.query();
ownersLoop = [];
while (grOwnership.next()) {
//Get the value of the Divisional Application Owner and convert it to a string
var divisionalApplicationOwner = grOwnership.u_business_owner + '';
//If there is already an existing entry, remove the duplicate entry
if (ownersLoop.indexOf(divisionalApplicationOwner) == -1) {
//Add the single entry to the ownersLoop
ownersLoop.push(divisionalApplicationOwner);
gs.eventQueue('lbg.notify.reassign_new_owner_DAO', grOwnership, grOwnership.u_business_owner.manager.toString(), grOwnership.u_business_owner.getDisplayValue());
}

//Get the value of the Business Application Steward and convert it to a string
var businessApplicationSteward = grOwnership.u_cmdb_data_steward + '';
//If there is already an existing entry, remove the duplicate entry
if (ownersLoop.indexOf(businessApplicationSteward) == -1) {
//Add the single entry to the ownersLoop
ownersLoop.push(businessApplicationSteward);
gs.eventQueue('lbg.notify.reassign_new_owner_BAS', grOwnership, grOwnership.u_cmdb_data_steward.manager.toString(), grOwnership.u_cmdb_data_steward.getDisplayValue());
}

//Get the value of the Technical Application Owner and convert it to a string
var technicalApplicationOwner = grOwnership.u_custodian + '';
//If there is already an existing entry, remove the duplicate entry
if (ownersLoop.indexOf(technicalApplicationOwner) == -1) {
//Add the single entry to the ownersLoop
ownersLoop.push(technicalApplicationOwner);
gs.eventQueue('lbg.notify.reassign_new_owner_TAO', grOwnership, grOwnership.u_custodian.manager.toString(), grOwnership.u_custodian.getDisplayValue());
}
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@matthew_hughes 

any update to this?

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader