Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need to create Business rule to auto populate fields based on condition

suuriya
Tera Contributor
Hi,
 
I have a requirement,
 
A) A Business Rule will be created to auto-populate and update data into new records when the record is created or migrated into the {Network Appliance Hardwares} [cmdb_ci_net_app_server] table, with the below conditions.
1) WHEN the [Name] contains "POLY":
a) The [Managed By Group] field will be populated as: "SP-Video-Conferencing"
b) The [Support Group] field will be populated as: "SP-Video-Conferencing"
c) The [Owned By] field will be populated as the [Manager] of Group: [SP-Video-Conferencing]
 
B) A Business Rule will be created to auto-populate and update data into existing records on the the {Network Appliance Hardwares} [cmdb_ci_net_app_server] table WHEN there is an update to the record [Manager] changes in group: [SP-Video-Conferencing].
1) WHEN the [Name] contains "POLY":
a) The [Owned By] field will be updated to the new [Manager] of Group: [SP-Video-Conferencing]

 

Please help me with the script....How we can achieve this

 

Thanks in Advance

1 ACCEPTED SOLUTION

Craig Gruwell
Mega Sage

Hi suuriya,

 

You'll want to use two different business rules to accomplish this.  Refer to attachments (of course your sys_ids will differ so you'll want to update accordingly).

 

 

View solution in original post

2 REPLIES 2

Craig Gruwell
Mega Sage

Hi suuriya,

 

You'll want to use two different business rules to accomplish this.  Refer to attachments (of course your sys_ids will differ so you'll want to update accordingly).

 

 

Hi @Craig Gruwell 

 

For First case i tried with this script

(function executeRule(current, previous /*null when async*/) {
 
var name_contains_poly_lowercase =current.name.toLowerCase();
    var name_contains_poly = name_contains_poly_lowercase.indexOf("poly");
var gr_server = new GlideRecord("cmdb_ci_net_app_server");
gr_server.addQuery('sys_id',current.sys_id);
gr_server.query();
if(gr_server.next())
{
if (name_contains_poly!=-1) 
{
        gr_server.managed_by_group ="5283669d9cf6200000dd41eb0f5c1dfa"; 
        gr_server.support_group = "5283669d9cf6200000dd41eb0f5c1dfa"; 
        gr_server.owned_by = gr_server.managed_by_group.manager;
gr_server.update();
    }
}
})(current, previous);