Transform Map Multiple Source Fields Map to The Same Reference

eackley
Tera Contributor

I have a transform Map that uses a csv source file to update the visual task board.

 

The problem I am having is that the csv contains multiple headers that point to the Task reference in the VST Card Table e.g assigned to, description, short description.

 

I transform the entries as below:

eackley_0-1750175059104.png

Where card_title is task.short_description.

 

How do I include additional mappings to task.assigned_to & task.description in the same transform map when the map will only allow 1 mapping to each task reference?

eackley_1-1750175196308.png

 

 

2 ACCEPTED SOLUTIONS

YaswanthKurre
Giga Guru

Hi @eackley ,

 

when you're working with a Transform Map and trying to map multiple fields from a CSV source to a referenced record, you're limited by the fact that you can only map one field directly to a reference field (e.g., task).

However, you can still update multiple fields on the referenced task record using a Transform Script.

 

Use an onAfter Transform Script

Here’s how you can do it:

  1. In your Transform Map, map the task reference field (e.g., task) to the appropriate column (like short_description).
  2. Then, use an onAfter script to update additional fields on the referenced Task record.

Sample script:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var taskGR = new GlideRecord('task');
    if (taskGR.get(source.task)) { //build your own query to pull the task record that needs to be updated based on source
        // Update additional fields
        taskGR.description = source.description;
        taskGR.assigned_to = source.assigned_to;
        taskGR.update();
    }


})(source, map, log, target);

 

Please mark this as helpful and correct if this resolves your issues.

 

Thanks,

Yaswanth

 

 

 

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@eackley 

you cannot set dot walked field using field map.

For that you can use onAfter transform script and query that task record and then set the assigned to and short description field

Something like this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var taskRec = target.task.getRefRecord();
    var incomingDescription = source.u_description;
    if (incomingDescription)
        taskRec.description = incomingDescription;

    var incomingAssignedToUser = source.u_assigned_to;
    var gr = new GlideRecord("sys_user");
    gr.addQuery("user_name", incomingAssignedToUser);
    gr.query();
    if (gr.next()) {
        taskRec.assigned_to = gr.getUniqueValue();
        taskRec.update();
    }

})(source, map, log, target);

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

View solution in original post

3 REPLIES 3

YaswanthKurre
Giga Guru

Hi @eackley ,

 

when you're working with a Transform Map and trying to map multiple fields from a CSV source to a referenced record, you're limited by the fact that you can only map one field directly to a reference field (e.g., task).

However, you can still update multiple fields on the referenced task record using a Transform Script.

 

Use an onAfter Transform Script

Here’s how you can do it:

  1. In your Transform Map, map the task reference field (e.g., task) to the appropriate column (like short_description).
  2. Then, use an onAfter script to update additional fields on the referenced Task record.

Sample script:

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

var taskGR = new GlideRecord('task');
    if (taskGR.get(source.task)) { //build your own query to pull the task record that needs to be updated based on source
        // Update additional fields
        taskGR.description = source.description;
        taskGR.assigned_to = source.assigned_to;
        taskGR.update();
    }


})(source, map, log, target);

 

Please mark this as helpful and correct if this resolves your issues.

 

Thanks,

Yaswanth

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@eackley 

you cannot set dot walked field using field map.

For that you can use onAfter transform script and query that task record and then set the assigned to and short description field

Something like this

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

    // Add your code here
    var taskRec = target.task.getRefRecord();
    var incomingDescription = source.u_description;
    if (incomingDescription)
        taskRec.description = incomingDescription;

    var incomingAssignedToUser = source.u_assigned_to;
    var gr = new GlideRecord("sys_user");
    gr.addQuery("user_name", incomingAssignedToUser);
    gr.query();
    if (gr.next()) {
        taskRec.assigned_to = gr.getUniqueValue();
        taskRec.update();
    }

})(source, map, log, target);

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

This was helpful but I do have a few issues I am having a hard time with.

 

1) The intent behind this data import is to populate a VTB with Cards. When I run my transform map with your script, it creates a task for each csv record. However, the cards are not added to the lane on the VTB. I was thinking that maybe it is because the import is creating generic tasks and I would need to set them somehow as vtb_task? 

 

Below is a sample line of the csv and the board that should populate the maintenance lane

eackley_0-1750451009510.pngeackley_1-1750451159704.png

 

I set all coalesce to false as well to test

 

eackley_2-1750451300533.png

 

Script that I copied from you, but I changed the query to look for name

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

	var taskRec = target.task.getRefRecord();
	//taskRec.sys_class_name = "vtb_task";

	var incomingDescription = source.u_description;

	if(incomingDescription)
		taskRec.description = incomingDescription;
	
	
	var incomingAssignedToUser = source.u_assigned_to;
	var gr = new GlideRecord("sys_user");
	gr.addQuery("name", incomingAssignedToUser);
	gr.query();
	if(gr.next()){
		taskRec.assigned_to = gr.getUniqueValue();	
		taskRec.update();
	}

})(source, map, log, target);

2) When the tasks are created, they are copying the short description and setting that string as the task number. Is there a method to create a unique number and set that as the task number?