Copy variables from one HR Task to other

JohnnySnow
Kilo Sage

Hi Team,

 

I have 2 HR Tasks, I want to copy all the variables present in the HR Task 1 to HR Task 2. In HR Task 2 there are no variables, so ideally these variables are to be inserted from HRT1. Can someone suggest how to achieve this?

(These HR Tasks are created from Record producer & HR Template)

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.
1 ACCEPTED SOLUTION

JohnnySnow
Kilo Sage

Hi All,

 

var sourceTask = new GlideRecord('sn_hr_core_task');
sourceTask.get('sys_id', '7f1f56b81b80fr10ff7b76ebdc4bcbd9');

var targetTask = new GlideRecord('sn_hr_core_task');
targetTask.get('sys_id', '21ae12781b80f510wf7b76ebdc4bcb7d');


var newID = '';
var ans = new GlideRecord('question_answer');
var gr = new GlideRecord('question_answer');
gr.addEncodedQuery('table_sys_id=' + sourceTask.getUniqueValue());
gr.query();
while (gr.next()) {
    ans.initialize();
    ans.table_sys_id = targetTask.getUniqueValue();
    ans.order = gr.order;
    ans.value = gr.value;
    ans.question = gr.question;
    ans.table_name = targetTask.getTableName();
    newID = ans.insert();
    gs.info("aj: the new sys id " + newID);
}

I achieved it with the above code. 

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

2 REPLIES 2

Ravi Chandra_K
Kilo Patron
Kilo Patron

Hey @JohnnySnow 

Greetings!

Could you please elaborate the requirement.

What is the relationship between task1 and task 2.

If the second tasks are there already in the system, you have to use fix script.

if the second tasks are to be generated at the time of creation of first task, then you can use after insert business rule.

Please hit the thumb and Mark as correct based on Impact!!

 

Kind Regards,

Ravi Chandra

JohnnySnow
Kilo Sage

Hi All,

 

var sourceTask = new GlideRecord('sn_hr_core_task');
sourceTask.get('sys_id', '7f1f56b81b80fr10ff7b76ebdc4bcbd9');

var targetTask = new GlideRecord('sn_hr_core_task');
targetTask.get('sys_id', '21ae12781b80f510wf7b76ebdc4bcb7d');


var newID = '';
var ans = new GlideRecord('question_answer');
var gr = new GlideRecord('question_answer');
gr.addEncodedQuery('table_sys_id=' + sourceTask.getUniqueValue());
gr.query();
while (gr.next()) {
    ans.initialize();
    ans.table_sys_id = targetTask.getUniqueValue();
    ans.order = gr.order;
    ans.value = gr.value;
    ans.question = gr.question;
    ans.table_name = targetTask.getTableName();
    newID = ans.insert();
    gs.info("aj: the new sys id " + newID);
}

I achieved it with the above code. 

Thanks
Johnny

Please mark this response as correct or helpful if it assisted you with your question.