If Statement in Transform Script

martin_kohler
Kilo Contributor

Hi,

I am struggeling with a transform script and I hope you can help me. The situation is that during an LDAP consolidation project two different LDAPs need to be imported into ServiceNow. The only possible coalesce attribute is email, however some accounts from the old LDAP should not be overwritten by the new LDAP import. All records that only exist in the new LDAP should, always be updated. I added a new attribute "LDAP_tempuser" to identify accounts that should be overwritten and I set up the following onBefore script to restrict the update process:

if (action == "update" && target.ldap_server != "newLDAP" && target.u_ldap_tempuser == false) {

  ignore = true;

}

My expectation is that:

  • If all conditions within the if clause are fulfilled, the record is ignored
  • If any of the conditions within the if clause is not fulfilled, the existing record is updated

However, the transform ignores all records, regardless of the if statement above and I cannot see why. Any ideas?

The attached screenshot shows the intended logical flow if that helps.

Thanks in advance for your help!

1 ACCEPTED SOLUTION

James_Neale
Mega Guru

Hey Martin,



target.ldap_server is a reference field so "newLDAP" actually needs to be the sys_id of the newLDAP server you have created.



var ldap_server = "32424a11dbba22002686da94ce96194b"; // newLDAP


if (action == "update" && target.ldap_server != ldap_server && target.u_ldap_tempuser == false) {


  ignore = true;


}



Right now, nothing is being inserted because that field would never equal "newLDAP".



Cheers,


James


View solution in original post

8 REPLIES 8

Hello,



thank you for your reply. The transform history shows that one record was ignored. In the corresponding log entries in the related list, there is nothing about "ignore". Or am I looking at the wrong place for the log?



Kind regards


Hello Martin,



Navigate to the import set and open the import set that you have recently opened and in the bottom of the form, you will get import set record, there you can check in the comments



find_real_file.png


Thank you. It says "Row transform ignored by onBefore script". As the onBefore script I posted above is the only onBefore Script, something is wrong there. Any ideas?


Hi Martin,



Sorry, I don't see any wrong in your before transform map.



May be both the condition are satisified , so why ignored. To ensure put gs.log for the both the values.



if (action == "update" && target.u_ldap_tempuser == false) {


  ignore = true;


}