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

Please help me with the XML Import issue.

Ereshkigal
Tera Contributor

I want to import Incident records from a remote environment to a local environment.

I created a DataSource based on the following document and ran the import.

https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/import-sets/concept/...

I was able to import it, but there are some problems.

  1. If the Group information is different between remote and local, the business rule "Abort changes on group" will be executed and it will not be possible to import.(If the group information does not match, I want to empty Assignment Group and Assigned to)
  2. I created a Transform Script in the above document, but because of that Script, it is the same as the remote sys_id when importing, so I can not import the record once imported. (I want to import the updated part as well)
  3. Newly added related records such as Incident Task should not be imported.

How can I solve these problems with Transform Script?

Thank you!

Business Rule:Abort changes on group(Incident)

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var assigned_to = current.assigned_to;
	var assignment_group = current.assignment_group;

	var grp = new GlideRecord('sys_user_grmember');
	grp.addQuery('group.sys_id', assignment_group);
	grp.addQuery('user', assigned_to);
	grp.query();

	if(!grp.hasNext())
	{
		gs.addErrorMessage(gs.getMessage("Assigned to user {0} must be member of Assignment group {1} ",[assigned_to.getDisplayValue(),assignment_group.getDisplayValue()]));
		current.setAbortAction(true);
	}

})(current, previous);

Transform Script:OnBefore

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

	// Add your code here
	if(action == "insert"){
		target.setNewGuidValue(source.u_sys_id);
	}

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

 

find_real_file.png

1 ACCEPTED SOLUTION

@Ereshkigal 

Got it. There is a concept known as "Coalesce" which means below:

The coalesce option allows you to update existing target table records when transforming import data.

The coalesce option on a field map allows you to specify if the selected Target field should be used to coalesce on when import set records are transformed. If the field map Coalesce checkbox is selected, when the import set row is transformed the instance checks for an existing record in the target table that has the same value in the Target field as the import set row Source field.

If an existing record with a matching value in the target table is found, that record is updated. If no matching record is found, then a new record is created in the target table.
 
Please refer to below doc for more info on this:
 
https://docs.servicenow.com/bundle/quebec-platform-administration/page/administer/import-sets/concept/c_ImportSetCoalesce.html
 
So based on your Transform Map configuration, decide a field which can act as a Coalesce here, I believe Number can be one attribute which you can use here and you just need to make the Number Field Map Coalesce as True which should solve your issue and will update existing record and not create new record as shown below:
 
Like for example, I have shown below for Category field, similarly you can do it for Number field:
 
find_real_file.png
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

9 REPLIES 9

shloke04
Kilo Patron

Hi @Ereshkigal 

Please let me know if you have a follow up query on this, else if your query is resolved then please mark the answer as correct and close this thread for others.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Thank you for answering!!

The above answer was very helpful.

I still have a problem.

I would like to borrow some knowledge about scripts below.

Based on the above document, the process of issuing a draft locally with the same Sys ID at the time of import is described.

However, once you have created a draft, you will not be able to import it locally for updates that have been made remotely.

For the remote updates, I want to update the local ones as well after importing.

However, due to lack of knowledge about scripting, I cannot solve it by myself.

Help me!

Thank you!

Hi @Ereshkigal 

Sure will assist you further. The above lines mentioned by you is not clear to me on what are you trying to build here.

Can you please explain your requirement clearly and couple of screenshot will help me understand better and assist you further.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi.

If you import 3 times, even if it is the same record, it will be created 3 times.

Isn't it possible to import this by updating it to one record?

Thank you!

find_real_file.png

@Ereshkigal 

Got it. There is a concept known as "Coalesce" which means below:

The coalesce option allows you to update existing target table records when transforming import data.

The coalesce option on a field map allows you to specify if the selected Target field should be used to coalesce on when import set records are transformed. If the field map Coalesce checkbox is selected, when the import set row is transformed the instance checks for an existing record in the target table that has the same value in the Target field as the import set row Source field.

If an existing record with a matching value in the target table is found, that record is updated. If no matching record is found, then a new record is created in the target table.
 
Please refer to below doc for more info on this:
 
https://docs.servicenow.com/bundle/quebec-platform-administration/page/administer/import-sets/concept/c_ImportSetCoalesce.html
 
So based on your Transform Map configuration, decide a field which can act as a Coalesce here, I believe Number can be one attribute which you can use here and you just need to make the Number Field Map Coalesce as True which should solve your issue and will update existing record and not create new record as shown below:
 
Like for example, I have shown below for Category field, similarly you can do it for Number field:
 
find_real_file.png
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke