Onbefore Transform map not updating the record, only inserting even though matches with theCondition

Pradeep Patel1
Tera Contributor

 

Following is my field map

PradeepPatel1_1-1719862773395.png

following is onbefore script

here I am checking if entity and current_ram combination exits, if yes then update the record.

I am mapping ram with the expected ram

PradeepPatel1_2-1719862981532.png

if combination does not exits then create new record

PradeepPatel1_3-1719863117694.png

for reference this is the table and following is the form

PradeepPatel1_4-1719863179173.png

 

Following is the script

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    var up = new GlideRecord("sn_risk_advanced_risk_assessment_scope");
    up.addEncodedQuery("entity.nameSTARTSWITH"+ source.u_entity + "^risk_assessment_methodology.nameSTARTSWITH" + source.u_current_ram);
    up.query();
    if(up.next())
    {
        action = 'update';
    }
    else{
        ignore = true;
    }
})(source, map, log, target);

 

 

6 REPLIES 6

Marco0o1
Tera Sage

Hi @Pradeep Patel1 ,

 

You can just not use a scripted action and just put your u_expected_ram and u_entity as a Coalesce fields, this will have a similar result:

 

Marco0o1_0-1719868229349.png

If that doesnt work to you maybe you can try not use a onbefore script and change to just run the script at the start because your script[onBefore] run when the record was already created:

 

Marco0o1_2-1719868411426.png

Regards,

Marco

Hi @Marco0o1 ,

Tried running through run script still inserting record. I just want to update the record rather than inserting it.

Deepak Shaerma
Kilo Sage

Hi @Pradeep Patel1 

Create a onBefore Transform Script and use the code below:

if(action == 'insert'){
ignore = true;
}

Also make a field coalesce true through which you want to update the record.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards
Deepak Sharma 



Hi @Deepak Shaerma 

Actually I can not use coalesce here, I want to check current_ram column with ram from target table, if combination exists then update it with expected RAM, can I update it in the script rather than Ignoring it.