how to write condition if u_current_ram is not empty then only return sys_id

Prathamesh Cha1
Tera Contributor

Hi Team,

I don't want to return or run this script current RAM from excel sheet or staging table is empty

 

PrathameshCha1_0-1723024647123.png

PrathameshCha1_0-1723024819582.png

 

 

answer = (function transformEntry(source) {

    // Add your code here
    if(source.u_current_ram != ""){
    var retRam = new GlideRecord("sn_risk_advanced_risk_assessment_methodology");
    retRam.addEncodedQuery("name=" + source.u_current_ram + "^state=2");
    retRam.query();
    if(retRam.next()){
    return retRam.sys_id; // return the value to be put into the target field
    }
    }

})(source);

 

 

3 REPLIES 3

Satishkumar B
Giga Sage
Giga Sage

@Prathamesh Cha1 try this:

 

answer = (function transformEntry(source) {
    // Check if u_current_ram is not empty
    if (source.u_current_ram) {
        var retRam = new GlideRecord("sn_risk_advanced_risk_assessment_methodology");
        retRam.addEncodedQuery("name=" + source.u_current_ram + "^state=2");
        retRam.query();
        if (retRam.next()) {
            return retRam.sys_id; // Return the value to be put into the target field
        }
    }
    // Return null or an empty value if no record is found or u_current_ram is empty
    return null;
})(source);

 

 

 

…………………………………………........................................................................................
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

…………………………………………........................................................................................

Hi @Satishkumar B , It is still skipping the record

PrathameshCha1_0-1723026539482.png

 

@Prathamesh Cha1 try adding log to check if it returns a value.
Ensure that the u_current_ram field's data type matches what you're querying against. For instance, if name in sn_risk_advanced_risk_assessment_methodology is a string field, ensure that source.u_current_ram is also a string. Mismatched data types could cause the query to fail silently.