generate csv file

GPavanKumK
Tera Contributor

 hi 

i'm trying to generate through flow designer as flow it working but it not generate through rtask 

 

var rowsFromRequest = [];
var row = '';
var returnBox = new GlideRecord('sc_req_item');
if(returnBox.get(fd_data.trigger.request_item.sys_id)){
 
     var ordernum = returnBox.getDisplayValue("request");
 
    var equipment_req = fd_data._1__get_catalog_variables.select_the_primary_device;
    var str = JSON.stringify(equipment_req);
    var dataarray = JSON.parse(str);
    gs.info("Pavan285 : "+ dataarray);
   
   if (dataarray && dataarray.length > 0 && dataarray[0]) {
    gs.info("Pavan285 : " + dataarray[0].display_name);
   }
    for(var i = 0; i < dataarray.length; i++){
   gs.info("Pavan285 : er  "+ dataarray[i].display_name + "RD "+ dataarray[i].replacement_device);
         
    //Construct row for CSV
    var row = escapeCSV(returnBox.getValue('number')) + ',' + //RITMNumber
    escapeCSV(fd_data._1__get_catalog_variables.select_device) + ',' + //Select device
    escapeCSV(fd_data._1__get_catalog_variables.who_is_currently_using_the_device.getDisplayValue()) + ',' + //who is currently using device
    escapeCSV(fd_data._1__get_catalog_variables.carrier) + ',' + //Carrier
//'"",' + //Carrier
    escapeCSV(fd_data._1__get_catalog_variables.cellular_number_found_in_device_settings) + ',' +  //Phone
    escapeCSV(fd_data._1__get_catalog_variables.imei_1_imei_2_number_found_in_device_settings.toString()) + ',' + //Address2
    escapeCSV(fd_data._1__get_catalog_variables.street_address) + ',' + // Street Address   
    escapeCSV(fd_data._1__get_catalog_variables.city) + ',' + //City
    escapeCSV(fd_data._1__get_catalog_variables.state_ref) + ',' + //State
    escapeCSV(fd_data._1__get_catalog_variables.zip_code) + ',' + //Zip 
    escapeCSV(getAssetName(dataarray[i].replacement_device,'Replacement Device')) + ','+ //IMEI
    escapeCSV(dataarray[i].display_name,'Display Name');//
    
   
  //  '"",' + //IMEI
    //'""' //IMEI2;
 
rowsFromRequest.push(row);
    }
}
 
 
 
var json = {
    headers: 'RITMNumber,Device Type,Who is currently using the device?,carrier,Cellular Number (found in device settings),IMEI 1/ IMEI 2 Number (found in device settings),Street Address,City,State,Zip Code,Replacement Device(SerialNumber),Display Name\r\n',
    rows: rowsFromRequest
}
 
return json;
 
 
 
function escapeCSV(raw) {
   var value = (raw + '').replace(/"/g,'""');   // escape all double quotes
   value = '"' + value + '"';   // if value has special characters, enclose in double quotes
   return value;
}
function getAssetName(sysID){
var alm = new GlideRecord("alm_asset");
if (alm.get(sysID))
return alm.getDisplayValue();
return "";
 
}                                                                                                                                                                                       
6 REPLIES 6

Naveen20
ServiceNow Employee

Possible issues i see

Wrong trigger pills -> fd_data.trigger.request_item.sys_id only exists on a RITM-triggered flow. From an sc_task flow, the trigger is the taskthat path is undefined, so returnBox.get(...) fails and you exit silently.

Missing/renamed catalog variable pills -> fd_data._1__get_catalog_variables.* is auto-generated by a
"Get Catalog Variables" step in the RITM flow. The rtask flow either doesn't have that step, has it numbered differently (_2_, _3_...), or has it bound to a different RITM reference.
Those pills resolve to undefined, and your row-building silently produces empty values
.

GPavanKumK
Tera Contributor

how to solve this Error: Cannot read property "0" from null,Detail: Cannot read property "0" from null

and getting this error in flow context.

while test flow it able to generate the data

Ankur Bawiskar
Tera Patron

@GPavanKumK 

flow is on which table?

share some screenshots

what do you mean by this line -> but it not generate through rtask

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

GPavanKumK_0-1777443359143.png