Lookup field does not attach case to newly created tasks

Posted by Paulh0763 on 29-Jan-2015 14:39

I have an object script trigger that creates 6 different tasks based on the Case Type of a newly created Case. If Case Type equals "ReRun", the 6 tasks are created. The tasks create perfectly except for the lookup field on the task record. I believe this is happening because the ID of that field on the case is "0" and the system cannot catch up quick enough. I have tried to create a delayed trigger of 1 minuted to attach the case on the record but that does not work either. Any suggestion would be helpful. Not sure if this is even possible? 

All Replies

Posted by Godfrey Sorita on 29-Jan-2015 14:57

Hi Paul,

This should be possible. I need more information on how you create "task" records, though. Can you attach the code on your object script?


Posted by Paulh0763 on 29-Jan-2015 15:03

The tasks are created using a workflow action, so when the case is of case type "Rerun" and saved, the user has the option to create the ReRun tasks using the workflow. Once performed the case status is then changed to ReRun Tasks Created. The code is as follows but the case does not attach even though when you debug it the case number shows...

rbv_api.getFieldValue("case8", {!id}, "case_type___rerun")

if('{!case_type#id}' == '26573005'){

var dueDate = new Date('{!createdAt}');

var a = new Array();

a["R529135"] = "{!R12466576}";

a["R15532410"] = "{!case_number}";

a["taskSubject"] = "Review Payroll Package";

a["assigned_to"] = "{!assigned_to}";

a["dueDate"] = dueDate;

a["R529644"] = "26593922";

a["status"] = "Not Started";

var newId = rbv_api.createRecord("task", a);

rbv_api.print("Created record with id: "+newId);

var b = new Array();

b["R529135"] = "{!R12466576}";

b["R15532410"] = "{!case_number}";

b["taskSubject"] = "Follow up with Client";

b["assigned_to"] = "{!assigned_to}";

b["dueDate"] = dueDate;

b["R529644"] = "26593922";

b["status"] = "Not Started";

var newId1 = rbv_api.createRecord("task", b);

rbv_api.print("Created record with id: "+newId1);

var c = new Array();

c["R529135"] = "{!R12466576}";

c["R15532410"] = "{!case_number}";

c["taskSubject"] = "Roll Back / Copy Payroll";

c["assigned_to"] = "{!assigned_to}";

c["dueDate"] = dueDate;

c["R529644"] = "26593922";

c["status"] = "Not Started";

var newId2 = rbv_api.createRecord("task", c);

rbv_api.print("Created record with id: "+newId2);

var d = new Array();

d["R529135"] = "{!R12466576}";

d["R15532410"] = "{!case_number}";

d["taskSubject"] = "Process Re-Run Payroll";

d["assigned_to"] = "{!assigned_to}";

d["dueDate"] = dueDate;

d["R529644"] = "26593922";

d["status"] = "Not Started";

var newId3 = rbv_api.createRecord("task", d);

rbv_api.print("Created record with id: "+newId3);

var e = new Array();

e["R529135"] = "{!R12466576}";

e["R15532410"] = "{!case_number}";

e["taskSubject"] = "Destroy Printed Payroll";

e["assigned_to"] = "{!assigned_to}";

e["dueDate"] = dueDate;

e["R529644"] = "26593922";

e["status"] = "Not Started";

var newId4 = rbv_api.createRecord("task", e);

rbv_api.print("Created record with id: "+newId4);

var f = new Array();

f["R529135"] = "{!R12466576}";

f["R15532410"] = "{!case_number}";

f["taskSubject"] = "Print Invoice for A/R";

f["assigned_to"] = "{!assigned_to}";

f["dueDate"] = dueDate;

f["R529644"] = "26593922";

f["status"] = "Not Started";

var newId5 = rbv_api.createRecord("task", f);

rbv_api.print("Created record with id: "+newId5);


Posted by Godfrey Sorita on 30-Jan-2015 09:26

What is the relationship cardinality between case and task object? Although unlikely, if your relationship cardinality is incorrectly (e.g. Many Case To One Task) only the last task record will be attached to the case record.

In your code, can you pinpoint which field holds the lookup field of case? Can you try replacing the value with "{!id}"? This will relate the current record to the newly created tasks.

Posted by Paulh0763 on 30-Jan-2015 09:47

One Case to Many Tasks - the integration name is R15532410 of the Lookup Case field on Task. I will try what you suggested with ID and see if that works.

Posted by Paulh0763 on 30-Jan-2015 09:57

Thanks Godfrey the ID worked! Sometimes it is that simple and we just do not see it!

Posted by Godfrey Sorita on 30-Jan-2015 10:10

You're welcome! :-)

This thread is closed