Data Transfer between two tables using Transform Script

Neha Rani4
Tera Contributor
i want the  fields to synchronize between Hr profile table and Job table so that we have same data that is coming from quantum. 
in the transform map we need to add a tranform script to sync up the data with job table.
Below is the script that i have created on onStart :
    gs.info('Transform map @@@ ' +source.u_contract_num);
    var sync_data = new GlideRecord('sn_hr_core_job');
    sync_data.initialize();
    sync_data.u_contract_number = source.u_contract_num;
    sync_data.u_hr_status = source.u_assig_status_code;
    sync_data.user = source.u_name;
    gs.info('Transform map @@@ ' +source.u_contract_num);
    sync_data.insert();
 
Whenever I am Transform the data , it is not showing anything....maybe the script is not working as expected as i used log to check this and data is not geting in the desired table.
In the transform History ,it is not showing any import logs.
When i checked in the system logs it shows the message only which is "Transform map @@@ undefined".
 
1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Neha Rani4 ,

The issue you are encountering seems to be the order of execution.
Try onBefore or onAfter-

Ensuring that the field we are accessing from source are properly mapped.

Now try the below code-

(function runTransformScript(source, map, log, target) {
    if (source.u_contract_num && source.u_assig_status_code && source.u_name) {
        var sync_data = new GlideRecord('sn_hr_core_job');
        sync_data.initialize();
        sync_data.u_contract_number = source.u_contract_num;
        sync_data.u_hr_status = source.u_assig_status_code;
        sync_data.user = source.u_name;
        sync_data.insert();
        gs.info('Transform map successful for contract number: ' + source.u_contract_num);
    } else {
        gs.error('Source fields are undefined. Contract number: ' + source.u_contract_num);
    }
})(source, map, log, target);

 

If my response has resolved your query, please consider giving it a thumbs up ‌‌ and marking it as the correct answer‌‌!

 

Thanks & Regards,

Sanjay Kumar

View solution in original post

8 REPLIES 8

Hi @Community Alums 

I have tried the approach you suggested but still facing the same issue.

Community Alums
Not applicable

Hi @Neha Rani4 ,

 

It looks like the mappings are not proper. can you please review it once and if possible share it here. Source and target, both should have the fields that you are using.

 

Also check the application scopes, if both are in same scope.

Try adding few logs in the script and check what all data is flowing.

 

Thanks,

Sanjay Kumar

The Mapping was correct...It was just I need to change the event from onStart to onBefore.It is working now.

 

Thanks alot.

Community Alums
Not applicable

That's amazing...!!

 

Regards,

Sanjay