Update on work notes returning as 'Undefined'

matthew_hughes
Kilo Sage

I've written the following script within my business rule to state that a field has been updated alongside the name of the Business Application Steward:

 

(function executeRule(current, previous /*null when async*/) {
var businessApplicationSteward = current.getValue('u_cmdb_data_steward');
var technicalApplicationOwner = current.getValue('u_custodian');
if ((current.u_business_application_type.changes() && gs.getUserID() == businessApplicationSteward)) {
current.work_notes = 'The Business Applicaion Type field has been updated by the Business Application Steward '+ businessApplicationSteward.name;
}

})(current, previous);

 

However when I do that, I get the following outcome:

 
The Business Applicaion Type field has been updated by the Business Application Steward undefined
 
I was just wondering if somebody could explain what I'm doing wrong and I need to do to get the display name of the user
1 ACCEPTED SOLUTION

matthew_hughes
Kilo Sage

I've found the solution by doing the following:

 

//If the Heritage field changes and was updated by the Application Service Steward
if ((current.u_heritage.changes() && gs.getUserID() == applicationServiceSteward)) {
current.work_notes = 'The Heritage field has been updated by the Application Service Steward '+ applicationServiceStewardName;
}

View solution in original post

6 REPLIES 6

Karan Chhabra6
Mega Sage
Mega Sage

Hi @matthew_hughes ,

 

getValue will return the sys_id of the reference field, to get the display name of the user, use getDisplayValue, please try with the code below:

(function executeRule(current, previous /*null when async*/) {
var businessApplicationSteward = current.u_cmdb_data_steward.getDisplayValue();
var technicalApplicationOwner = current.u_custodian;
if ((current.u_business_application_type.changes() && gs.getUserID() == businessApplicationSteward)) {
current.work_notes = 'The Business Applicaion Type field has been updated by the Business Application Steward '+ businessApplicationSteward.name;
}

})(current, previous);

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

I tried that but it didn't work

On above script, work note line should be like below as .name is not required(won't work) as you already have display value in businessApplicationSteward

 

current.work_notes = 'The Business Applicaion Type field has been updated by the Business Application Steward '+ businessApplicationSteward;

 

 

Prince Arora
Tera Sage
Tera Sage

@matthew_hughes 

 

Can you please try below:

 

 

(function executeRule(current, previous /*null when async*/) {
var businessApplicationSteward = current.u_cmdb_data_steward ;
var technicalApplicationOwner = current.u_custodian ;
if ((current.u_business_application_type.changes() && gs.getUserID() == businessApplicationSteward)) {
current.work_notes = 'The Business Applicaion Type field has been updated by the Business Application Steward '+
(current.u_cmdb_data_steward).getDisplayValue();
}

})(current, previous);

 

I hope "businessApplicationSteward " stores the sys_id of some user right

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.