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

Slava Savitsky
Giga Sage

You don't need a script for this. Coalescing by multiple fields should work fine.

Hi @Slava Savitsky ,

I tried doing that, still either it insert's or ignores

That means the values don't match. Check if there are any leading or trailing spaces that prevent matching.

Actually I am able successfully able to create new records, as entity and RAM both are reference fields and while we are only importing exiting entities and existing RAM's if they doesn't exit then I am rejecting that record, using choice action = reject, tried with create also still inserting new record