Pulling the sys_id of a record that hasn't been inserted yet and writing to another field on a different table

Ken Lombard
Giga Guru

I have a request that I'm wondering if it is functionally possible.  They would like a button on the Idea form that will move the Idea into another state (easy enough), and then direct the user to a new Project form, without actually inserting a record yet.  I've been able to accomplish that part, but what I would also like to do is copy back the sys_id of that record that has not yet been inserted to the task field on the Idea.  That way, if they insert the project record, it will be linked to the Idea.  

Here's the code for the UI Action as it is currently:

var projGr = new GlideRecord('pm_project');
projGr.newRecord();
projGr.setValue('phase', 'Concept');
current.task = projGr.sys_id;
current.state = '6';
current.update();
action.openGlideRecord(projGr);

This will do everything we need, short of writing back the project sys_id to the task field on the Idea record.  It seems like a sys_id is assigned to a record before insertion, so it may just be that the database cannot commit that value to the task field until the record has been inserted.  I do already have a solution that will insert first and then write back the task value to the Idea record, but was just curious if what I mentioned above was possible.

 

1 ACCEPTED SOLUTION

Figured out a workaround.  I ended up storing the sys_id of the Idea onto a custome reference field in the project, then set up an after BR to run after insert of the project and if there is a value in that field, it writes it back to that Idea task field. 

View solution in original post

5 REPLIES 5

Figured out a workaround.  I ended up storing the sys_id of the Idea onto a custome reference field in the project, then set up an after BR to run after insert of the project and if there is a value in that field, it writes it back to that Idea task field.