Here is a working(at least in my instance) sample of creating a Task against a specific Service Request using the jtf_tasks_pub.create_task API.
create or replace procedure xxx_create_task as
v_user_id number;
v_resp_id number;
v_appl_id number;
l_msg_count number;
l_msg_data varchar2(2000);
l_return_status varchar2(1);
l_task_id number;
v_resource_id number;
v_incident_id number;
begin
--the task is being created against Service Request#1000004940
select incident_id
into v_incident_id
from cs_incidents_all_b
where incident_number = '1000004940';
--Service Request#1000004940 already has some tasks, the task which we are going to create will
--have the same owner as the previous tasks
select distinct owner_id
into v_resource_id
from jtf_tasks_vl
where source_object_id = v_incident_id;
--required for fnd_global.apps_initialize()
select user_id
into v_user_id
from apps.fnd_user
where upper(user_name) in ('TEST_USER');
--required for fnd_global.apps_initialize()
select fa.application_id, frt.responsibility_id
into v_appl_id, v_resp_id
from apps.fnd_user_resp_groups furg,
apps.fnd_application fa,
apps.fnd_responsibility_tl frt
where fa.application_short_name = 'CSS'
and upper(frt.responsibility_name) =
upper('Test Responsibility')
and fa.application_id = frt.application_id
and furg.responsibility_application_id = fa.application_id
and furg.responsibility_id = frt.responsibility_id
and furg.user_id = v_user_id
and rownum = 1;
fnd_global.apps_initialize(user_id => v_user_id,
resp_id => v_resp_id,
resp_appl_id => v_appl_id);
--call the API
jtf_tasks_pub.create_task(p_api_version => 1.0,
p_init_msg_list => fnd_api.g_true,
p_commit => fnd_api.g_false,
p_task_name => 'My Task',
--this is the task_type_id for 'My Task' obtained from jtf_task_types_vl
p_task_type_id => 11269,
--task_staus_id obtained from jtf_task_statuses_vl
p_task_status_id => 10,
--task_priority_id obtained from jtf_task_priorities_vl
p_task_priority_id => 3,
p_owner_type_code => 'RS_EMPLOYEE',
p_owner_id => v_resource_id,
p_show_on_calendar => 'Y',
p_planned_start_date => sysdate,
p_planned_end_date => sysdate,
p_source_object_type_code => 'SR',
p_source_object_id => v_incident_id,
p_source_object_name => '1000004940',
p_date_selected => 'P',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_task_id => l_task_id);
if l_return_status <> fnd_api.g_ret_sts_success then
dbms_output.put_line('Return Status aa= ' || l_return_status);
dbms_output.put_line('Return Status dd= ' || fnd_api.g_ret_sts_success);
dbms_output.put_line('l_msg_count aa= ' || l_msg_count);
if l_msg_count > 0 then
l_msg_data := null;
for i in 1 .. l_msg_count loop
l_msg_data := l_msg_data || ' ' || fnd_msg_pub.get(1, 'F');
dbms_output.put_line('l_msg_data aa= ' || l_msg_data);
end loop;
fnd_message.set_encoded(l_msg_data);
dbms_output.put_line(l_msg_data);
end if;
rollback;
else
dbms_output.put_line('Task Id = ' || l_task_id);
dbms_output.put_line('Return Status = ' || l_return_status);
commit;
end if;
end;
On executing the procedure in my system, I get the following output.
SQL> set serveroutput on;
SQL>
SQL> begin
2 xxx_create_task;
3 end;
4 /
Task Id = 157917
Return Status = S
PL/SQL procedure successfully completed
SQL>
create or replace procedure xxx_create_task as
v_user_id number;
v_resp_id number;
v_appl_id number;
l_msg_count number;
l_msg_data varchar2(2000);
l_return_status varchar2(1);
l_task_id number;
v_resource_id number;
v_incident_id number;
begin
--the task is being created against Service Request#1000004940
select incident_id
into v_incident_id
from cs_incidents_all_b
where incident_number = '1000004940';
--Service Request#1000004940 already has some tasks, the task which we are going to create will
--have the same owner as the previous tasks
select distinct owner_id
into v_resource_id
from jtf_tasks_vl
where source_object_id = v_incident_id;
--required for fnd_global.apps_initialize()
select user_id
into v_user_id
from apps.fnd_user
where upper(user_name) in ('TEST_USER');
--required for fnd_global.apps_initialize()
select fa.application_id, frt.responsibility_id
into v_appl_id, v_resp_id
from apps.fnd_user_resp_groups furg,
apps.fnd_application fa,
apps.fnd_responsibility_tl frt
where fa.application_short_name = 'CSS'
and upper(frt.responsibility_name) =
upper('Test Responsibility')
and fa.application_id = frt.application_id
and furg.responsibility_application_id = fa.application_id
and furg.responsibility_id = frt.responsibility_id
and furg.user_id = v_user_id
and rownum = 1;
fnd_global.apps_initialize(user_id => v_user_id,
resp_id => v_resp_id,
resp_appl_id => v_appl_id);
--call the API
jtf_tasks_pub.create_task(p_api_version => 1.0,
p_init_msg_list => fnd_api.g_true,
p_commit => fnd_api.g_false,
p_task_name => 'My Task',
--this is the task_type_id for 'My Task' obtained from jtf_task_types_vl
p_task_type_id => 11269,
--task_staus_id obtained from jtf_task_statuses_vl
p_task_status_id => 10,
--task_priority_id obtained from jtf_task_priorities_vl
p_task_priority_id => 3,
p_owner_type_code => 'RS_EMPLOYEE',
p_owner_id => v_resource_id,
p_show_on_calendar => 'Y',
p_planned_start_date => sysdate,
p_planned_end_date => sysdate,
p_source_object_type_code => 'SR',
p_source_object_id => v_incident_id,
p_source_object_name => '1000004940',
p_date_selected => 'P',
x_return_status => l_return_status,
x_msg_count => l_msg_count,
x_msg_data => l_msg_data,
x_task_id => l_task_id);
if l_return_status <> fnd_api.g_ret_sts_success then
dbms_output.put_line('Return Status aa= ' || l_return_status);
dbms_output.put_line('Return Status dd= ' || fnd_api.g_ret_sts_success);
dbms_output.put_line('l_msg_count aa= ' || l_msg_count);
if l_msg_count > 0 then
l_msg_data := null;
for i in 1 .. l_msg_count loop
l_msg_data := l_msg_data || ' ' || fnd_msg_pub.get(1, 'F');
dbms_output.put_line('l_msg_data aa= ' || l_msg_data);
end loop;
fnd_message.set_encoded(l_msg_data);
dbms_output.put_line(l_msg_data);
end if;
rollback;
else
dbms_output.put_line('Task Id = ' || l_task_id);
dbms_output.put_line('Return Status = ' || l_return_status);
commit;
end if;
end;
On executing the procedure in my system, I get the following output.
SQL> set serveroutput on;
SQL>
SQL> begin
2 xxx_create_task;
3 end;
4 /
Task Id = 157917
Return Status = S
PL/SQL procedure successfully completed
SQL>