Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Can i change the source field Value using onBefore Transform Script?

RamjiP611320747
Tera Contributor

1. I have a scenario where i have to remove field value which contains "not availabe" to transformed as empty, source script for every field could not be the best scenario.

2. i wanted to change the source field itself from "not available" to "", can i do this using onBefore Transform Script.

function removeNotAvailable() {
        var naLookup = {
            'NA': true,
            'N/A': true,
            'NOT AVAILABLE': true
        };
        var sourceGr = new GlideRecord("u_test_supplier_data");
        sourceGr.get(source.sys_id);
        gs.info("Updated source field: "+ source.sys_id)
 
        var value = (source.u_diversity_status_temporary).trim().toUpperCase();
       
 
        if (naLookup[value]) {
            gs.info("FOUND THE NOT AVAIALBLE: " + value)
            sourceGr.u_diversity_status_temporary = "hello";
            sourceGr.update();  
            gs.info("Updated source field: "+ sourceGr.u_diversity_status_temporary)
        }
    }
 
    removeNotAvailable();
2 REPLIES 2

Ankur Bawiskar
Tera Patron

@RamjiP611320747 

not possible in onbefore script to manipulate source data

why not use onBefore transform script to handle your logic based on what's there in source field value?

💡 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  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

RamjiP611320747
Tera Contributor

why not use onBefore transform script to handle your logic based on what's there in source field value?


i am already using the onBefore transform script to manipulate data, could you be more descriptive here