Transform map generating empty records along with records with data

samadam
Kilo Sage

I have a transform to import records and after importing it generates extra records that are null: I have Onafter script

(function transformRow(source, target, map, log, isUpdate) {

  var cart = new Cart(GlideGuid.generate(null));
  var item = cart.addItem('e97b9be9877df110809aa9b60cbb1234'); 
  cart.setVariable(item, 'short_description', 'TEST Request');
  cart.setVariable(item, 'requested_for', '6582020a1b9744903aa6da49bc4bac1b');
  cart.setVariable(item, 'what_is_being_requested','Other Service');
  cart.setVariable(item, 'site_code', '9332a4431bc7d410bdaa6579bc4bcb83');
  cart.setVariable(item, 'device', 'Workstaion');
  cart.setVariable(item, 'customer_contact_number', '234-450-4412');
  cart.setVariable(item, 'what_service_is_required', source.u_notes);
  cart.setVariable(item, 'best_days', 'Monday - Friday 0800-1700');
  cart.setVariable(item, 'name', 'details located in description');
  cart.setVariable(item, 'assignment_group', '129c1a0c1b569890e403a93be54bc123');
  var rc = cart.placeOrder();
 


})(source, target, map, log, action==="insert");
Any suggestions?
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@samadam 

transform map is on which target table?

why you didn't write the logic in onBefore transform script to create REQ and RITM?

To ignore records getting created in target table and if your requirement is only to create REQ and RITM using Cart API then use this

Create onBefore Transform script

(function transformRow(source, target, map, log, isUpdate) {

    ignore = true;

})(source, target, map, log, action === "insert");

💡 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Tanushree Maiti
Mega Sage

It seems there is issue with coalescing. Can you double check and confirm .

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@samadam 

transform map is on which target table?

why you didn't write the logic in onBefore transform script to create REQ and RITM?

To ignore records getting created in target table and if your requirement is only to create REQ and RITM using Cart API then use this

Create onBefore Transform script

(function transformRow(source, target, map, log, isUpdate) {

    ignore = true;

})(source, target, map, log, action === "insert");

💡 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

yashkamde
Kilo Sage

Hello @samadam ,
can you please wrap your code in a try-catch-block to see whether any code issue lead to that result:

(function transformRow(source, target, map, log, isUpdate) {

    try {
        var cart = new Cart(GlideGuid.generate(null));
        var item = cart.addItem('e97b9be9877df110809aa9b60cbb1234');  
        cart.setVariable(item, 'short_description', 'TEST Request');
        cart.setVariable(item, 'requested_for', '6582020a1b9744903aa6da49bc4bac1b');
        cart.setVariable(item, 'what_is_being_requested','Other Service');
        cart.setVariable(item, 'site_code', '9332a4431bc7d410bdaa6579bc4bcb83');
        cart.setVariable(item, 'device', 'Workstaion');
        cart.setVariable(item, 'customer_contact_number', '234-450-4412');
        cart.setVariable(item, 'what_service_is_required', source.u_notes);
        cart.setVariable(item, 'best_days', 'Monday - Friday 0800-1700');
        cart.setVariable(item, 'name', 'details located in description');
        cart.setVariable(item, 'assignment_group', '129c1a0c1b569890e403a93be54bc123');
        
        var rc = cart.placeOrder();
    }
    catch (e) {
        gs.error(e);
        ignore = true;    
    }

})(source, target, map, log, action === "insert");

 

 

If my response helped mark as helpful and accept the solution.

samadam
Kilo Sage

I have the transform map on RITM and added ignore=true and changed to OnBefore and it worked.