The CreatorCon Call for Content is officially open! Get started here.

Import Parent and Child Tasks on Import Set

Andrew Bettcher
Kilo Sage

Hi,

I have project data in another system that I need to import into ServiceNow. I can get the Parent project data in but then I need to add child tasks from the same data set. I can't work out a way of associating the imported sub-tasks to the parent because the relationship is defined between the two by the parent field on a sub-task. I obviously can't import a valid parent field entry from my source data because it only exists in ServiceNow.

I import contract/asset relationships onto a separate table (Assets Covered). Any ideas how I can do this for project and project tasks?

Regards, 

7 REPLIES 7

Andrew Bettcher
Kilo Sage

Hi Lavlesh,

 

We were wanting to do it all in one hit. The extract from the external system contains information for both the Parent and Child tasks and so we have one transform map that creates the parent projects and then run another transform that creates the tasks. Same principle I guess and so your solution would work.

 

I looked at the scripts avaialble but have no experience of import scripts and so didn;t know when it would need to be ran. Thank you again Lavlesh.

Once I've got a working script I'll post it on here. 😉

Andrew Bettcher
Kilo Sage

OK. Took a while for us to get the source data sorted so I could begin to test my import method. It doesn't work but I'm so close.

I feel like there is something fundamental that I'm missing. Here is my onBefore transform script:

 

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
	
	var x = source.u_id;
	var gr = new GlideRecord('pm_project');
	gr.addQuery('u_netsuite_project_number', x);
	gr.query();
	
	if(gr.next()){
		log.info(gr.getValue('number'),x);
	        gr.getValue('u_netsuite_project_number'));
		target.parent = gr.number;
		
	}}
	
)(source, map, log, target);

 

The import log shows that the right source id is being matched with the project number from ServiceNow but the parent field isn't being populated with the PRJ number to complete the child parent relationship.

Weirdly though, some of my test records DO get something in the parent field, namely TASK0020115. I have no idea where this comes from. We don't use records numbered this way. Clicking the link takes me to a record that looks like this:

find_real_file.png

Can anyone suggest where I'm going wrong?

Am I using the function right? I mean, do I want to push the number to the target or do I want to create a new entry on the source and transform it onto my project task records?

 

Regards,

Andrew Bettcher
Kilo Sage

Haha. Always the way.

Typing this out for the forum caused me to think about it in a new way in order to verbalise it and.....simply changing target.parent to source.parent sorted it.

I guess because it onBEFORE right so it needs to act on the data before it is transformed into the target table.

I can picture the hardcore script kiddies laughing at an old fool for spending an entire day wrestling with this conundrum only to have it turn out to be child's play.

 

BTW - I spent some time on the Oracle users forum and I have to say that the ServiceNow user forums are a LOT friendlier. Most of the answers to peoples questions over there are met with people pointing out breaches of forum etiquette or making newbies feel daft.

I've never felt that on this forum. Thank you all.