How to update only one target field and ignore the other fields in Field maps (Transform Map)

WA1
Kilo Sage

Hello, 

I have created onBefore Transform Script to update target fields in certain conditions for example : 

// If type is "A" & discovery is "B" --> Update only the target field discovery
        if (source.u_type == "A" && target.discovery == "B") {
            target.discovery = "A";
        }

When I test, I find that in the target record, all fields are updated but I want only the "discovery" field to be updated.

So how can I ignore the update of the other fields in the Field Maps section and only update one field "discovery" ?

Thank you

1 ACCEPTED SOLUTION

Abhijit4
Mega Sage

Hi,

There is only one way to achieve this, you will have to update target record in onBefore script and mark ignore as true.

Please try below script,

 if (source.u_type == "A" && target.discovery == "B") {
            target.discovery = "A";
            target.update();
            ignore=true;
        }

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

View solution in original post

10 REPLIES 10

Sulabh Garg
Mega Sage
Mega Sage

Hello

you may plan to write two "On before" script with different order as shown below

1) First on-before script - Order as 100  

// If type is "A" & discovery is "B" --> Update only the target field discovery

if (source.u_type == "A" && target.discovery == "B") {

target.discovery = "A";

}

2) Second on-before script - Order as 200

if (target.discovery == "A") {

ignore=true;

}

 

Please Mark Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Hello, 

It didn't work, the update was ignored.

ersureshbe
Giga Sage
Giga Sage

Hi, You can change your code as like below.

 

if (source.u_type == "A" && target.discovery == "B")

{ target.discovery = "A";

}else {

ignore = true;

}

Please mark as correct answer if it helped.

Regards,

Suresh.

Regards,
Suresh.

Hello, 

It's about the first condition if it's true I want to only update target.discovery and ignore the rest of fields.

I don't think the else is the solution, if I add it I won't be able to update fields if (source.u_type != "A" || target.discovery != "B" ) because I still have other conditions to manage.