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

Populate display name field using business rules

Bargavi
Mega Expert

Hi,

I am trying to populate field_1 with the value "abc field_2" using business rule.

I have tried couple of Before business rule scripts, none of them are working

1. used concatenation

var field_2 = current.u_field_2;

var x = "abc";

var sum = x +' '+field_2;

current.field_1= sum;

2.

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord(table_name);
gr.query();

var field_2 = current.u_field_2;
while(gr.next())
{

current.field_1= 'abc' + current.field_2 + ' ';

}
})(current, previous);

can anyone point me in right direction, please.

-Thanks

14 REPLIES 14

Hi,



I have a onBefore Business rule to populate Name field on cmdb_ci_network_adapter.


The name field should be populated by "text123 MAC address" from the form.


ex: test123 00:00:00:00:00



function onBefore(current, previous /*null when async*/) {



var macAddress = current.cmdb_ci.mac_address;
var x = "abc";
current.name = x +'-'+macAddress;


}



-Thanks


Do you have any condition or filter in BR. Also share the order and domain info of the BR. And is it on Insert or on update or on both.


I do not have any conditions.



Table : Network Adapter(cmdb_ci_network_adapter)


when : before


order 10000


On insert and on update



-thanks


I added mac address in the below mentioned ci record.


find_real_file.png


Then wrote a BR given below.


find_real_file.png


Script as below



(function executeRule(current, previous /*null when async*/) {



current.mac_address= 'abc'+' '+current.cmdb_ci.mac_address.toString();



})(current, previous);




Creating a new Network Adapter.


find_real_file.png


After inserting the value we have mac address as given below.



find_real_file.png



Hope this helps.



Regards


Ujjawal


Thanks for the detail, appreciate it.


I got it working. I had to perform update on record to display the results.



Thanks everyone for your responses.



-thanks.