OnStart Transform Script

Apoorva A H
Tera Contributor

Hi Team,

I have added a condition in onstart transform script where it should give an error message if the excel file contains more than 50 records just a  example. So the Condition is satisfied and entered to the if loop but not able to see the error message.

Below is the code written in Script

 

var limit = parseInt(gs.getProperty('x_amspi_payroll_up.acn.bulk_request.payroll_asset_limit'));
    var sourceCount = source.getRowCount();
    if(sourceCount > limit ){
        log.error(' Number of records in source and limit ' + sourceCount +  ' '  + limit,'acnBulkRequest.'+map.name);
        ignore = true ;
     }
Can you help me on this error message, why I'm not able to get error.
 
4 REPLIES 4

ranepratiks
Tera Expert

Hello  @Apoorva A H ,

You can try below script :

var limit = parseInt(gs.getProperty('x_amspi_payroll_up.acn.bulk_request.payroll_asset_limit'));
var sourceCount = source.getRowCount();

 

log.info('Script started. Source count: ' + sourceCount + ', Limit: ' + limit, 'acnBulkRequest.' + map.name);

 

if (sourceCount > limit) {
    var message = 'Error: Number of records (' + sourceCount + ') exceeds the allowed limit (' + limit + ').';
    log.error(message, 'acnBulkRequest.' + map.name);
    ignore = true;
    throw message;
}

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Apoorva A H 

error message will be seen in system logs and import logs.

did you check if system property "glide.importlog.log_to_table" is true?

Import sets properties 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Apoorva A H 

try this

1) use import_set object which is the import set object, it will give you count and not the source object

2) try using error = true and error_message along with log.error()

3) ensure that system property is true "glide.importlog.log_to_table"

var limit = parseInt(gs.getProperty('x_amspi_payroll_up.acn.bulk_request.payroll_asset_limit'));
var sourceCount = import_set.getRowCount();
if (sourceCount > limit) {
    log.error('Number of records in source and limit ' + sourceCount + ' ' + limit, 'acnBulkRequest.' + map.name);
    error = true;
    error_message = 'Import aborted: Number of records (' + sourceCount + ') exceeds the allowed limit (' + limit + ').';
    ignore = true;
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Apoorva A H 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader