Can we convert field type from String to reference field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 09:38 AM
Hi All ,
i am working on a scoped app , and there is a field called 'Spoke to' which is a free text field and logged in user manually enters his name in it .
I have a requirement to change the name of field to 'Recorded by' (which is done ) and also autopopulate this field with logged in user id .
1st question : can we auto populate a text field with logged in user id using javascript:gs.getUserID() ??
As per my knowledge , it has to be a reference field to sys_user table to use javascript:gs.getUserID()
2nd question : if above method is not possible , then can we convert a string field to reference field and use javascript:gs.getUserID() ???
right now there are 2012 lab records in which 'Recorded by' field is populated manually by user worked on that lab record and 1440 records in which this field is empty becos user forgot to enter his name . .
Please suggest ur advice on this . Thanks for looking into this issue .
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 09:58 AM
Hi Sachin,
please confirm if below is right
var gr = new GlideRecord('x_ohhr_lab_client_lab_client_form '); // lab form i am working on
gr.EncodedQuery('recorded_by=NULL'); //recorded by is a new reference field i created.
gr.addQuery();
gr.query();
while(gr.next())
{
var copy1 = gr.getDisplayValue(' client_name_for_visit '); // existing recorded by field which has data
gr.setValue(' recorded_by ', copy1); // copying copy1 data into recorded_by field .
gr.update(); //Save it
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2019 10:26 AM
Please use below script as per your configuration
var gr = new GlideRecord('x_ohhr_lab_client_lab_client_form'); // lab form i am working on
gr.addEncodedQuery('recorded_by=NULL'); //recorded by is a new reference field i created.
gr.query();
while(gr.next()) {
var usr = new GlideRecord('sys_user');
usr.addQuery('name',gr.client_name_for_visit);
usr.query();
while(usr.next()){
gr.recorded_by = usr.sys_id;
gr.update(); //Save it
}
}
Regards,
Sachin