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

Create reference record in related table using GlideRecord

Cpitre
Tera Contributor

That subject was probably ambiguous, but I'm trying to populate the phone record table (sn_openframe_phone_log_list) using a business rule on the case record from the CSM plugin. On the case record, I have the below part of a code built out. I am able to populate the phone log table with this, but the "task" column is a reference field that links the phone log record with the case record. No matter what I throw at it though, I can't get the phone log table record to populate with the current case ID. Any suggestions?

 

 

var gr = new GlideRecord('sn_openframe_phone_log');
gr.initialize();
gr.task = current.number;
gr.insert();

 

 

1 ACCEPTED SOLUTION

Bert_c1
Kilo Patron

the record's 'sys_id' (gr.task = current.sys_id) is needed. Since the task field on the sn_openframe_phone_log table is a "Reference" field.

View solution in original post

4 REPLIES 4

Bert_c1
Kilo Patron

the record's 'sys_id' (gr.task = current.sys_id) is needed. Since the task field on the sn_openframe_phone_log table is a "Reference" field.

Cpitre
Tera Contributor

Much appreciated! I was rather close with one of my iterations. I knew it probably wasn't overly complicated. 

Bert_c1
Kilo Patron

You may need  "gr.task = current.sys_id.toString();". And I'm guessing you are using a Business Rule defined on the "sn_customerservice_case" table.

 

You can use "gs.info("myBusinessRule: creating record with task with reference to " + current.number + ".");" to see what in Scripts Log Statement module that the BR logic executes.

 

And change the "gr.insert()" to "var result = gr.insert();" and then log: 

gs.info("myBusinessRule: New record sys_id is " + result + ".");

Cpitre
Tera Contributor

Your assumption was correct. It is a Business Rule defined on the "sn_customerservice_case" table.

 

I had it working with sys_id.toString() in November, but when trying it now i'm back to square one with not being able to populate with current case record. I have the rule to run on display (though I have tried the others without success). I was able to verify with logging that the value of the sys_id that the script is pulling is correct, but the phone log table is either not populating at all or is populating with a default task value.