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

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

Hello, 

Thank you it worked.

Have a nice day!

Hi @Abhijit4 ,

 

Could you please give your inputs on it. I tried your code too in my use case to update only one field, but it was not working.

https://www.servicenow.com/community/itsm-forum/how-to-update-only-one-field-from-transform-map/td-p...

Hey @Sironi , 

 

Your link is not working for me, looks like you have deleted your question. Let me know if you need any help.

 

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

Hello @Abhijit4 ,

 

i have a scenario where i have to update all other fields(including 2 source scripts) except one field via on before transform script on some conditions. 

Can it be done ?

 

Thanks & regards,

Subhasis