Checking for two coalesce not working hence writing script to check existing combination of twofiels

Pradeep Patel1
Tera Contributor

Hi All,

 

Here I am checking for entity and ram field

if "xx" entity with "yy" ram exits in the table it should update record.

if "xx" with "zz" it should insert,

if "ss" with "yy" still create new record.

 

Both fields are reference fields, already added name in the both source fields as reference field.

PradeepPatel1_0-1719678279247.png

already able to insert record but I want to update is same combination exits.

 

PradeepPatel1_1-1719678331848.png

 

list view

PradeepPatel1_2-1719678351062.png

 

above is the form view

successfully able to insert records please any one can help,

code

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var upd = new GlideRecord("sn_risk_advanced_risk_assessment_scope");
    upd.addEncodedQuery('entity.name=' + source.u_entity + '^risk_assessment_methodology.nameSTARTSWITH' + source.u_ram); //Check whether record exits with same combination of entity and RAM
    upd.query();
    if (upd.next()) {
        action = 'update';
    }
})(source, map, log, target);
 
tried running same code in explicit run script and onbefore script
7 REPLIES 7

Narsing1
Mega Sage

Hi,

Remove the existing coalesce and create a new script based one with the Target as sys_id.  You  can use the similar kind of code with the small change like this.

answer = (function transformEntry(source) {

    var upd = new GlideRecord("sn_risk_advanced_risk_assessment_scope");
    upd.addEncodedQuery('entity.name=' + source.u_entity + '^risk_assessment_methodology.nameSTARTSWITH' + source.u_ram); //Check whether record exits with same combination of entity and RAM
    upd.query();
    if (upd.next()) {
        return upd.sys_id.toString()
    } else {
        return -1;
    }

})(source);

Thanks,

Narsing

Hi @Narsing1 ,

 

I tried this script in both onBefore and explicit run script, still it didn't worked

Its a field map, not onbefore. Can you try like this.  Make all other coalesce false and mark this one as true.

Narsing1_0-1719709482513.png

Thanks,

Narsing