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.

How to prevent list collector field in transform map from being updated with invalid data

Kiran_25
Tera Expert

I have created a transform map and have a list collector field which I am able to update with invalid choices.  I've tried setting the choice action to ignore and reject but the field still gets updated. 

 

As a workaround I can restrict the import sheet to only allow the user to select valid choices but I also want restrict it in Servicenow so they can't enter any bad data. They should be able to select multiple choices and update these through the transform.

9 REPLIES 9

Unfortunately I havent had any luck with this. I have tried using a onBefore script & removing mapping. 

Also tried using a source script on the field mapping but still seeing invalid data being populated. 

The onBefore script I used is:

(function transformEntry(source, target, map, log, isUpdate) {
    // Skip insert if not an update
    if (!isUpdate) {
        ignore = true;
        return;
    }

    // Validate 'Type of HC Data'
    var validHCData = [
        'Other',
        'Technical / Procedural security arrangements',
        'Business Manager'
    ];
    if (!validHCData.includes(source.u_type_of_hc_data.toString())) {
        target.u_type_of_hc_data = ''; // or null
    }

    // Validate 'PCI DSS capacities'
    var validPCI = [
        'Service Provider',
        'Security Impacting',
        'Issuer',
        'Connected System'
    ];
    if (!validPCI.includes(source.u_pci_dss_capacities.toString())) {
        target.u_pci_dss_capacities = ''; // or null
    }
})(source, target, map, log, action === 'update');

 

@Kiran_25 

so when you added gs.info() what are your findings?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I'm seeing this in the logs: 

Kiran_25_0-1761317686580.png

The source field is being updated with 'Merchant, testing, testing1' despite the invalid data getting filtered. 

@Kiran_25 

you need to query sys_choice and see if that choice is present in list collector

then try to set the choice value using target object

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I have tried that and also made sure to test with choices that aren't present in list collector but experiencing the same issue still.  Not sure if there are any other workarounds for this