We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to set a field only on insert and still trigger a Business Rule on Transform Script ?

Mani_Mk
Tera Contributor

Hi everyone,

I have a requirement involving a Transform Map where I need to set a field value based on whether a record is inserted or updated.

Here’s the scenario: I’m loading incident data from Excel. The file can contain both existing and new incident records. If the incident already exists, I don’t want to change anything. But if it’s a new record, I need to set a custom resync field to “Yes”, which should trigger a Business Rule to pull data from an external API.

The issue is that the field value is not being set reliably during the transform.

If I set it using a field map script, the value updates, but the Business Rule that depends on it does not trigger as expected.

Has anyone faced a similar situation? What would be the best practice to conditionally set a field during transform while ensuring the related Business Rule executes properly?

Thanks in advance!

@Ankur Bawiskar  #servicenow #developer 

1 ACCEPTED SOLUTION

pratikjagtap
Giga Guru

Hi @Mani_Mk ,

Try below OnBefore transform script

(function runTransformScript(source, target, map, log, isUpdate) {

if (action == 'insert') {
target.u_resync = 'Yes';
}

})(source, target, map, log, action == 'update');

Use below BR conditions:

current.operation() == 'insert'
&& current.u_resync == 'Yes'

If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Pratik



View solution in original post

1 REPLY 1

pratikjagtap
Giga Guru

Hi @Mani_Mk ,

Try below OnBefore transform script

(function runTransformScript(source, target, map, log, isUpdate) {

if (action == 'insert') {
target.u_resync = 'Yes';
}

})(source, target, map, log, action == 'update');

Use below BR conditions:

current.operation() == 'insert'
&& current.u_resync == 'Yes'

If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Pratik