How to auto-populate number field with custom format in record producer

Amol Pawar
Tera Guru

Hi All,

I have a variable called 'ip_id' in a record producer. I want to auto-populate a number there when a user opens that record producer to create a record. In table I have written a business rule for this in table level but for record producer I need to create a catalog client script. I'll provide the BR script for reference. Please help me to implement the same functionality in the client script.

 

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

var num = "IA1";
var date= new GlideDate();
num = date.getByFormat('yy');
var iaNum = current.number.replace('-',num);
current.ip_id = iaNum;

})(current, previous);

 

Please guide me how to achieve this by client script.

 

Thanks in advance,

Amol

1 REPLY 1

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

You need to move this code in a script include and then call the script include from the client script of the record producer and it will work.

 

Just make sure that in the script include you glide the table as current will not work.

 

You can refer the below on how to call a script include from a client script

 

https://servicenow.com/community/developer-forum/calling-a-script-include-from-a-client-script/m-p/1...

 

Please mark my answer as correct  based on Impact.