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.

insert value with Busines Rule

Rafael Batistot
Kilo Patron

Hi Team

i have this simple code with Business Rule. This rule it's running in incident table

i want to when i open any incident record number of incident needs to be inserted in this field "u_activity_2"

But it's not can be like display, needs to be modification with this symbol because if i take an report this value will be there 

RafaelBatistot_0-1743198588498.png

 

I need to do it with BR not Client Script 
 

(function executeRule(current, previous /*null when async*/ ) {
    var incidentId = current.number;
	current.u_activity_2 = current.number;
})(current, previous);

 

Thank's advanced

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.
10 REPLIES 10

not work

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

Hi @Rafael Batistot ,

How did you tested? Have you created a new record? 

If not then create a new incident record and see if the field is set with the inc number.

Rafael Batistot
Kilo Patron

in this case i'm in Data Archive module, all the fields are not visible, and there's not possible to save ana data in this module
that's why i need to insert this values and save automatic. i've try with "current.updated()" but it's doesn't work as well 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.

Hi @Rafael Batistot 

 


Sorry I didn’t get you. You are saying that you won’t be able to create a new incident?

quanth
Tera Contributor

Hello!

- Since you are using a display Business Rule, the 'u_activity_2' field has already been displayed on the Incident form.

In this case, you can try to use an onLoad Client Script to set a value for the 'u_activity_2' field

var activityValue = 'some text';
g_gorm.setValue('u_activity_2', activityValue);

- In case 'u_activity_2' does not display on the form, let's try to use a before Business Rule to set a value for the 'u_activity_2' field after User Save/Submit the Incident form

var activityValue = 'some text';
current.setValue('u_activity_2', activityValue);