How to set Document ID field using GlideRecord

mukki
Kilo Contributor

Hi ,

I am trying to insert record using GliderRecord in table chat_message but i am not able to set the To and From field.I haven't worked with Documnet ID type fields.

Can anyone please suggest how i can populate those document id field using Glide Record

1 ACCEPTED SOLUTION

domaners
Kilo Guru

Hi Mukesh, the field is called to_id, so set current.to_id = sys_id. from_id is the name of the From field. You may also need to set the to_table and from_table with the name of the tables that the document is coming from as well, for instance:



current.to_id = incident.sys_id;


current.to_table = 'incident';


View solution in original post

12 REPLIES 12

mukki
Kilo Contributor

Hi Adam ,



Awesome solution, this resolved my issue.


I need one more help if any how you can advice, i am facing similar issue with chat_room table while i am trying to update the field Ref created by (ref_created_by) with another sys_id , it's not getting updated with new value via glide record.



Below is my code, can you suggest me what i am doing wrong here :



var chanRec = new GlideRecord('chat_room');


chanRec.addQuery('sys_id','fa5c5a5df12f7100328569e433ca694c');


chanRec.query();



if(chanRec.next()){


chanRec.ref_created_by = '9768443b2be3ad40b6b5756219da15da';


chanRec.update();


}


Great, glad I could help. I'm looking at your chat_room script and can't see too much wrong with it...



Where are your sys_id's coming from in this script? Sometimes I find that it's a good idea to cast object variables as string as I've had issues like that before:



if(chanRec.next()){


chanRec.ref_created_by = (String)'9768443b2be3ad40b6b5756219da15da';


chanRec.update();


}


mukki
Kilo Contributor

I am using sys_id of my own profile from sys_user table.But it's not changing the field value despite being a reference field.


mukki
Kilo Contributor

Hi Adam ,



Did you got   a chance to look in to this?


I am looking at this now and get the same issue. I'll update you when I work out why this is happening...