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

How to Skip the Update of a field in Transform Map or Run its Field-mapping Script

Brizky
Giga Expert

Hello, everyone.  

 

I have a phone number field in my Transform map that needs one of two things to happen.

 

  1. If the source Phone number is a specific value (i.e. '555-55-5555') then we don't update the target phone number.
  2. If the source phone number is anything else, run the script for that mapped field that will modify that phone number before updating the target phone number.

I've seen this post, Transform map script ignore particular field updat... - ServiceNow Community, which isn't exactly what my situation is.  And I looked up the precedence order for how scripts run during a transform.  But I can't figure out quite how to make this work for my situation.

Could someone point me in the right direction?

1 ACCEPTED SOLUTION

Alka_Chaudhary
Mega Sage
Mega Sage

Hello @Brizky ,

You can remove the field map for phone number and write on before transform script.

You can try the below script:-

if(source.phone_number != "555-555-5555") {
     target.phone_number = source.phone_number; 
}

Please Mark my answers Helpful & Accepted if I have answered your questions.

Thanks,

Alka

View solution in original post

8 REPLIES 8

OlaN
Giga Sage
Giga Sage

Hi,

So it sounds like you should always run the transform script, but depending on the source value different things should happen.

Something like this (pseudo-code)

if (source.getValue('somefield') == somecondition){
  // when the field is 555-5555 for example
  target.targetfield = '555-5555'; set the same value again for example
}
else {
  // your logic here that changes/sets the target field
}

The condition being met is where I have the confusion.  Because I don't want to touch the target field at all.  I want to leave that value alone and skip it.  But process all of my other fields.

Brizky
Giga Expert

Thank you both for the replies!

Vishal Birajdar
Giga Sage

Hi @Brizky 

 

On Field map entry, You can enable "Use source script" option & write a code as per your need.

 

 

answer = (function transformEntry(source) {

/* 1. Get the source value */

var sourceValue = source.your_field_name;

var newSourceValue;

if (sourceValue != '555-55-5555') {
    /* 2. Update the new source value as per your need */

    newSourceValue = "your_new_source_value";
    
	return newSourceValue;
} else {
         return sourceValue ;
}

})(source);

 

 

 

 

VishalBirajdar_0-1698155199257.png

 

So source value will be look as like below :

 

VishalBirajdar_1-1698155267035.png

 

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates