- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2020 06:31 AM
I have Transform Map to upload bulk data to TableB. There is a reference field in TableB which will hold unique number from TableA.
In OnStart : Create record to TableA and take unique number and map that number to TableB while transformation is happening (OnBefore)
gr.initialize();
gr.u_name = false;
var qNumber =gr.insert();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2020 01:03 AM
Hi Nirmala,
I think you cannot use global variables declared in onStart transform script to be used in the onBefore as per below link
https://hi.service-now.com/kb_view.do?sysparm_article=KB0676967
For your approach as all the imported records should have same value in Parent you can use below approach
1) use onComplete script so that it would run at the end when all transform happens
2) in that create a record in Table A
3) now query for all the target records from the import set table and update the field with the sys_id from step 2
Ensure you use setWorkflow(false) while updating to avoid triggering any business rule on Table B
Sample script below
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gr = new GlideRecord('TableA');
gr.initialize();
gr.u_name = false;
var qNumber =gr.insert();
var gr1 = new GlideRecord('import_set_table');
gr1.addQuery('sys_import_set', source.sys_import_set);
gr1.query();
while(gr1.next()){
var targetRecordSysId = gr1.sys_target_sys_id; // get the target record sys_id
var tableB = new GlideRecord('table B');
tableB.addQuery('sys_id', targetRecordSysId);
tableB.query();
if(tableB.next()){
tableB.<table_A_field> = qNumber;
tableB.setWorkflow(false);
tableB.update();
}
}
})(source, map, log, target);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2020 02:15 PM
Hi
Do you have an update on the example I gave above.
I guess this will solve the problem.
Let me know if that answered your question and mark my answer as correct and helpful.
BR Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2020 12:33 AM
Hi All,
Thank you for all your efforts to reply.
Still my requirement is not met. All these solutions are inserting new Parent ID for each one of the record which are inserted to Table B.
My requirement is bulkupload data to Table B, all the records from source must hold only one ParentID with them and parentid must be created in Table A before transform happens.
Kindly help with your suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2020 01:03 AM
Hi Nirmala,
I think you cannot use global variables declared in onStart transform script to be used in the onBefore as per below link
https://hi.service-now.com/kb_view.do?sysparm_article=KB0676967
For your approach as all the imported records should have same value in Parent you can use below approach
1) use onComplete script so that it would run at the end when all transform happens
2) in that create a record in Table A
3) now query for all the target records from the import set table and update the field with the sys_id from step 2
Ensure you use setWorkflow(false) while updating to avoid triggering any business rule on Table B
Sample script below
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var gr = new GlideRecord('TableA');
gr.initialize();
gr.u_name = false;
var qNumber =gr.insert();
var gr1 = new GlideRecord('import_set_table');
gr1.addQuery('sys_import_set', source.sys_import_set);
gr1.query();
while(gr1.next()){
var targetRecordSysId = gr1.sys_target_sys_id; // get the target record sys_id
var tableB = new GlideRecord('table B');
tableB.addQuery('sys_id', targetRecordSysId);
tableB.query();
if(tableB.next()){
tableB.<table_A_field> = qNumber;
tableB.setWorkflow(false);
tableB.update();
}
}
})(source, map, log, target);
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2020 11:12 PM
Is this question resolved or you need some more assistance?
if my answer helped you, kindly mark it as ✅ Correct & 👍Helpful so that it does not appear in unanswered list & close the thread.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2020 12:15 AM
Thank you Ankur.
It worked. Thanks a lot.